1 | |
2 | * List the file keys available in the workspace files storage (S3) |
3 | * |
4 | */ |
5 | export async function main( |
6 | workspace: string, |
7 | max_keys: string | undefined, |
8 | marker: string | undefined, |
9 | prefix: string | undefined |
10 | ) { |
11 | const url = new URL( |
12 | `${BASE_URL}/api/w/${workspace}/job_helpers/list_stored_files` |
13 | ); |
14 | for (const [k, v] of [ |
15 | ["max_keys", max_keys], |
16 | ["marker", marker], |
17 | ["prefix", prefix], |
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 |
|