Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Populate environment variables:
- `ISSUE_8895_COOLDOWN`: Seconds to wait before room creation ([matrix-org/synapse#8895])
- [Pretalx]:
- `PRETALX_RATE_LIMIT`: Rate limit in hertz
- `PRETALX_API_KEY`: API key to authenticate Pretalx requests (optional, only useful if you want to generate Matrix rooms before the schedule is published - this also probably won't work out of the box)
- [Sentry]:
- `SENTRY_DSN` (Optional): Data Source Name of Sentry project. If unset, error reporting is not enabled.

Expand Down
8 changes: 6 additions & 2 deletions src/lib/Pretalx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const origin = "https://pretalx.seagl.org";
const minTime = 1000 / Number(env("PRETALX_RATE_LIMIT"));

const limiter = new Bottleneck({ maxConcurrent: 1, minTime });
const fetch = limiter.wrap(unlimited);
const fetch: typeof unlimited = limiter.wrap(unlimited);

// Reference: https://docs.pretalx.org/api/fundamentals/#pagination
interface PaginatedResponse<T = {}> {
Expand Down Expand Up @@ -53,6 +53,7 @@ export const getTalks = async (event: string): Promise<Talk[]> => {
const url = `${origin}/api/events/${event}/talks/?limit=100`;
for await (const page of pages<TalksResponse>(url))
for (const { code, slot, state, title } of page)
// XXX: if you set PRETALX_API_KEY, it will return unscheduled social events that don't have a slot defined
talks.push({
id: code,
title,
Expand All @@ -77,7 +78,10 @@ async function* pages<Response extends PaginatedResponse>(
): AsyncGenerator<Response["results"]> {
let next: string | null = url;
do {
const response = (await (await fetch(next)).json()) as Response;
const authHeader = process.env["PRETALX_API_KEY"] ? {
"Authorization": `Token ${process.env["PRETALX_API_KEY"]}`
} : {};
const response = (await (await fetch(next, { headers: authHeader })).json()) as Response;
next = response.next;
yield response.results;
} while (next);
Expand Down