From 2127574a33019192dc84c8c4f1660e9c4fcd1a75 Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:50:36 -0400 Subject: [PATCH] Fix file extension handling --- functions/api/reports/submit.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/functions/api/reports/submit.ts b/functions/api/reports/submit.ts index 5069f79..abb5c3d 100644 --- a/functions/api/reports/submit.ts +++ b/functions/api/reports/submit.ts @@ -142,11 +142,14 @@ export async function onRequestPost(context: RequestContext) { const uploadUrlPromises: Promise[] = []; for (const file of files) { - const filePartes = file.name.split("."); - let fileExten = filePartes.at(-1); + const fileParts = file.name.split("."); + let fileExten = fileParts.at(-1); + + if (fileExten.toLowerCase() === "mov") + fileExten = "mp4" if ( - filePartes.length < 2 || + fileParts.length < 2 || ![ "mkv", "mp4", @@ -161,7 +164,6 @@ export async function onRequestPost(context: RequestContext) { "heif", "heic", "webp", - "mov", ].includes(fileExten.toLowerCase()) ) return errorResponse( @@ -209,15 +211,13 @@ export async function onRequestPost(context: RequestContext) { for (const urlResult of uploadUrlResults as PromiseFulfilledResult[]) { uploadUrls.push(urlResult.value); - let url = urlResult.toString().replace("t/", ""); + let url = urlResult.value.replace("t/", ""); const extension = (url.split(".").at(-1) as string).toLowerCase(); - if (["mkv", "mov", "wmv"].includes(extension)) { - // These are merely glorified mp4 containers - if (extension !== "mov") - await context.env.DATA.put(`videoprocessing_${url}.${extension}`, "1", { - expirationTtl: 600, - }); + if (["mkv", "wmv"].includes(extension)) { + await context.env.DATA.put(`videoprocessing_${url.replace(`.${extension}`, ".mp4")}`, "1", { + expirationTtl: 600, + }); url = url.replace(`.${extension}`, ".mp4"); }