1 | |
2 | type Assemblyai = { |
3 | apiKey: string; |
4 | }; |
5 | |
6 | * List transcripts |
7 | * Retrieve a list of transcripts you created. |
8 | Transcripts are sorted from newest to oldest. The previous URL always points to a page with older transcripts. |
9 |
|
10 | */ |
11 | export async function main( |
12 | auth: Assemblyai, |
13 | limit: string | undefined, |
14 | status: "queued" | "processing" | "completed" | "error" | undefined, |
15 | created_on: string | undefined, |
16 | before_id: string | undefined, |
17 | after_id: string | undefined, |
18 | throttled_only: string | undefined, |
19 | ) { |
20 | const url = new URL(`https://api.assemblyai.com/v2/transcript`); |
21 | for (const [k, v] of [ |
22 | ["limit", limit], |
23 | ["status", status], |
24 | ["created_on", created_on], |
25 | ["before_id", before_id], |
26 | ["after_id", after_id], |
27 | ["throttled_only", throttled_only], |
28 | ]) { |
29 | if (v !== undefined && v !== "" && k !== undefined) { |
30 | url.searchParams.append(k, v); |
31 | } |
32 | } |
33 | const response = await fetch(url, { |
34 | method: "GET", |
35 | headers: { |
36 | Authorization: "Bearer " + auth.apiKey, |
37 | }, |
38 | body: undefined, |
39 | }); |
40 | if (!response.ok) { |
41 | const text = await response.text(); |
42 | throw new Error(`${response.status} ${text}`); |
43 | } |
44 | return await response.json(); |
45 | } |
46 |
|