Remove gcloud upload url generator
This commit is contained in:
parent
a858a5f03e
commit
523b348978
@ -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({
|
||||
|
Loading…
x
Reference in New Issue
Block a user