1 | |
2 | type Gitbook = { |
3 | token: string; |
4 | }; |
5 | |
6 | * List all space revision files |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Gitbook, |
11 | spaceId: string, |
12 | revisionId: string, |
13 | page: string | undefined, |
14 | limit: string | undefined, |
15 | metadata: string | undefined, |
16 | computed: string | undefined, |
17 | ) { |
18 | const url = new URL( |
19 | `https://api.gitbook.com/v1/spaces/${spaceId}/revisions/${revisionId}/files`, |
20 | ); |
21 | for (const [k, v] of [ |
22 | ["page", page], |
23 | ["limit", limit], |
24 | ["metadata", metadata], |
25 | ["computed", computed], |
26 | ]) { |
27 | if (v !== undefined && v !== "" && k !== undefined) { |
28 | url.searchParams.append(k, v); |
29 | } |
30 | } |
31 | const response = await fetch(url, { |
32 | method: "GET", |
33 | headers: { |
34 | Authorization: "Bearer " + auth.token, |
35 | }, |
36 | body: undefined, |
37 | }); |
38 | if (!response.ok) { |
39 | const text = await response.text(); |
40 | throw new Error(`${response.status} ${text}`); |
41 | } |
42 | return await response.json(); |
43 | } |
44 |
|