diff --git a/README.md b/README.md index c86ad03..5e9f0a7 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/lib/Pretalx.ts b/src/lib/Pretalx.ts index 93b00af..1263123 100644 --- a/src/lib/Pretalx.ts +++ b/src/lib/Pretalx.ts @@ -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 { @@ -53,6 +53,7 @@ export const getTalks = async (event: string): Promise => { const url = `${origin}/api/events/${event}/talks/?limit=100`; for await (const page of pages(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, @@ -77,7 +78,10 @@ async function* pages( ): AsyncGenerator { 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);