Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove gcloud upload url generator
  • Loading branch information
regalijan committed Mar 23, 2024
1 parent a858a5f commit 523b348
Showing 1 changed file with 0 additions and 45 deletions.
45 changes: 0 additions & 45 deletions functions/gcloud.ts
Expand Up @@ -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({
Expand Down

0 comments on commit 523b348

Please sign in to comment.