0
Move a S3 file from one path to the other within the same bucket
One script reply has been approved by the moderators Verified
Created by hugo697 274 days ago Viewed 9356 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 274 days ago
1
/**
2
 * Move a S3 file from one path to the other within the same bucket
3
 *
4
 */
5
export async function main(
6
  workspace: string,
7
  src_file_key: string | undefined,
8
  dest_file_key: string | undefined
9
) {
10
  const url = new URL(
11
    `${BASE_URL}/api/w/${workspace}/job_helpers/move_s3_file`
12
  );
13
  for (const [k, v] of [
14
    ["src_file_key", src_file_key],
15
    ["dest_file_key", dest_file_key],
16
  ]) {
17
    if (v !== undefined && v !== "") {
18
      url.searchParams.append(k, v);
19
    }
20
  }
21
  const response = await fetch(url, {
22
    method: "GET",
23
    headers: {
24
      Authorization: "Bearer " + WM_TOKEN,
25
    },
26
    body: undefined,
27
  });
28
  if (!response.ok) {
29
    const text = await response.text();
30
    throw new Error(`${response.status} ${text}`);
31
  }
32
  return await response.json();
33
}
34