//native
type Discourse = {
apiKey: string;
defaultHost: string;
apiUsername: string;
};
/**
* Complete multipart upload
* Completes the multipart upload in the external store, and copies the
file from its temporary location to its final location in the store.
*/
export async function main(
auth: Discourse,
body: { unique_identifier: string; parts: unknown[] },
) {
const url = new URL(`https://${auth.defaultHost}/uploads/complete-multipart.json`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"API-KEY": auth.apiKey,
"API-USERNAME": auth.apiUsername,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago