1 |
|
2 | * list resources |
3 | * |
4 | */ |
5 | export async function main( |
6 | workspace: string, |
7 | page: string | undefined, |
8 | per_page: string | undefined, |
9 | resource_type: string | undefined, |
10 | resource_type_exclude: string | undefined |
11 | ) { |
12 | const url = new URL(`${BASE_URL}/api/w/${workspace}/resources/list`); |
13 | for (const [k, v] of [ |
14 | ["page", page], |
15 | ["per_page", per_page], |
16 | ["resource_type", resource_type], |
17 | ["resource_type_exclude", resource_type_exclude], |
18 | ]) { |
19 | if (v !== undefined && v !== "") { |
20 | url.searchParams.append(k, v); |
21 | } |
22 | } |
23 | const response = await fetch(url, { |
24 | method: "GET", |
25 | headers: { |
26 | Authorization: "Bearer " + WM_TOKEN, |
27 | }, |
28 | body: undefined, |
29 | }); |
30 | if (!response.ok) { |
31 | const text = await response.text(); |
32 | throw new Error(`${response.status} ${text}`); |
33 | } |
34 | return await response.json(); |
35 | } |
36 |
|