diff --git a/functions/gcloud.ts b/functions/gcloud.ts index 3d62c12..bf14ab4 100644 --- a/functions/gcloud.ts +++ b/functions/gcloud.ts @@ -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 { - 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 { const claimSet = btoa( JSON.stringify({