//native
type Vercel = {
token: string;
};
/**
* Get Deployment File Contents
* Allows to retrieve the content of a file by supplying the file identifier and the deployment unique identifier. The response body will contain a JSON response containing the contents of the file encoded as base64.
*/
export async function main(
auth: Vercel,
id: string,
fileId: string,
path: string | undefined,
teamId: string | undefined,
slug: string | undefined,
) {
const url = new URL(
`https://api.vercel.com/v7/deployments/${id}/files/${fileId}`,
);
for (const [k, v] of [
["path", path],
["teamId", teamId],
["slug", slug],
]) {
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.text();
}
Submitted by hugo697 428 days ago