//native
type Vercel = {
token: string;
};
/**
* Upload Deployment Files
* Before you create a deployment you need to upload the required files for that deployment. To do it, you need to first upload each file to this endpoint. Once that's completed, you can create a new deployment with the uploaded files. The file content must be placed inside the body of the request. In the case of a successful response you'll receive a status code 200 with an empty body.
*/
export async function main(
auth: Vercel,
teamId: string | undefined,
slug: string | undefined,
Content_Length?: string,
x_vercel_digest?: string,
x_now_digest?: string,
x_now_size?: string,
) {
const url = new URL(`https://api.vercel.com/v2/files`);
for (const [k, v] of [
["teamId", teamId],
["slug", slug],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "POST",
headers: {
...(Content_Length ? { "Content-Length": Content_Length } : {}),
...(x_vercel_digest ? { "x-vercel-digest": x_vercel_digest } : {}),
...(x_now_digest ? { "x-now-digest": x_now_digest } : {}),
...(x_now_size ? { "x-now-size": x_now_size } : {}),
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 428 days ago