1 | |
2 | * Download file to S3 bucket |
3 | * |
4 | */ |
5 | export async function main( |
6 | workspace: string, |
7 | file_key: string | undefined, |
8 | s3_resource_path: string | undefined, |
9 | resource_type: string | undefined |
10 | ) { |
11 | const url = new URL( |
12 | `${BASE_URL}/api/w/${workspace}/job_helpers/download_s3_file` |
13 | ); |
14 | for (const [k, v] of [ |
15 | ["file_key", file_key], |
16 | ["s3_resource_path", s3_resource_path], |
17 | ["resource_type", resource_type], |
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.text(); |
35 | } |
36 |
|