Remove gcloud upload url generator

This commit is contained in:
Regalijan 2024-03-22 21:39:53 -04:00
parent a858a5f03e
commit 523b348978
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -12,51 +12,6 @@ function stringToBuffer(str: string) {
return buffer;
}
export async function GenerateUploadURL(
env: Env,
path: string,
size: number,
fileExt: string,
origin: string,
): Promise<string> {
const accessToken = await GetAccessToken(env);
const contentTypes: { [k: string]: string } = {
gif: "image/gif",
m4v: "video/x-m4v",
mkv: "video/x-matroska",
mov: "video/mp4",
mp4: "video/mp4",
webm: "video/webm",
wmv: "video/x-ms-wmv",
};
const resumableUploadReq = await fetch(
`https://storage.googleapis.com/upload/storage/v1/b/portal-carcrushers-cc/o?uploadType=resumable&name=${encodeURIComponent(
path,
)}`,
{
headers: {
authorization: `Bearer ${accessToken}`,
origin,
"x-upload-content-type": contentTypes[fileExt],
"x-upload-content-length": size.toString(),
},
method: "POST",
},
);
if (!resumableUploadReq.ok)
throw new Error(
`Failed to create resumable upload: ${await resumableUploadReq.text()}`,
);
const url = resumableUploadReq.headers.get("location");
if (!url) throw new Error("No location header returned");
return url;
}
export async function GetAccessToken(env: Env): Promise<string> {
const claimSet = btoa(
JSON.stringify({