diff --git a/lib/actions/recordings.ts b/lib/actions/recordings.ts index 023aad3..85668af 100644 --- a/lib/actions/recordings.ts +++ b/lib/actions/recordings.ts @@ -410,7 +410,7 @@ export const getRecording = defineAction({ }) : null, gitlabConfigured() - ? recordUrl(recordKeys(rec), rec.startedAt).catch((error) => { + ? recordUrl(recordKeys(rec)).catch((error) => { emitErrorLog(error, { source: "gitlab record" }) return null }) diff --git a/lib/gitlab.ts b/lib/gitlab.ts index 2f80bc8..692ba38 100644 --- a/lib/gitlab.ts +++ b/lib/gitlab.ts @@ -12,29 +12,29 @@ export const gitlabConfigured = () => Boolean(process.env.GITLAB_API_TOKEN) type Epic = { web_url: string; description: string | null; state: string } /** The record's web URL for the first key found, or null. Searches the - * lab's epics that mention meet.winlab.tw, updated from a day before the - * recording started (filing a recording updates its record). */ -export async function recordUrl(keys: string[], since: Date) { + * lab's epics for each key in turn: the record links the recording on + * Nextcloud, not on meet.winlab.tw, so the key is the one text it is sure + * to hold. */ +export async function recordUrl(keys: string[]) { const token = process.env.GITLAB_API_TOKEN - if (!token || keys.length === 0) return null - const query = new URLSearchParams({ - search: "meet.winlab.tw", - include_descendant_groups: "true", - state: "all", - updated_after: new Date(since.getTime() - 86_400_000).toISOString(), - per_page: "100", - }) - const response = await fetch( - `${base()}/api/v4/groups/${encodeURIComponent(group())}/epics?${query}`, - { - headers: { "private-token": token }, - cache: "no-store", - signal: AbortSignal.timeout(8000), - } - ) - if (!response.ok) throw new Error(`GitLab ${response.status}`) - const epics = (await response.json()) as Epic[] + if (!token) return null for (const key of keys) { + const query = new URLSearchParams({ + search: key, + include_descendant_groups: "true", + state: "all", + per_page: "20", + }) + const response = await fetch( + `${base()}/api/v4/groups/${encodeURIComponent(group())}/epics?${query}`, + { + headers: { "private-token": token }, + cache: "no-store", + signal: AbortSignal.timeout(8000), + } + ) + if (!response.ok) throw new Error(`GitLab ${response.status}`) + const epics = (await response.json()) as Epic[] const marker = `request="${key}"` const found = epics.find((e) => e.description?.includes(marker)) if (found) return found.web_url