//native
type Box = {
token: string;
};
/**
* List parts
* Return a list of the chunks uploaded to the upload session so far.
The actual endpoint URL is returned by the [`Create upload session`](e://post-files-upload-sessions)
and [`Get upload session`](e://get-files-upload-sessions-id) endpoints.
*/
export async function main(
auth: Box,
upload_session_id: string,
offset: string | undefined,
limit: string | undefined,
) {
const url = new URL(
`https://api.box.com/2.0/files/upload_sessions/${upload_session_id}/parts`,
);
for (const [k, v] of [
["offset", offset],
["limit", limit],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago