Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix file extension handling
  • Loading branch information
regalijan committed Oct 19, 2023
1 parent 91ff428 commit 2127574
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions functions/api/reports/submit.ts
Expand Up @@ -142,11 +142,14 @@ export async function onRequestPost(context: RequestContext) {
const uploadUrlPromises: Promise<string>[] = [];

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",
Expand All @@ -161,7 +164,6 @@ export async function onRequestPost(context: RequestContext) {
"heif",
"heic",
"webp",
"mov",
].includes(fileExten.toLowerCase())
)
return errorResponse(
Expand Down Expand Up @@ -209,15 +211,13 @@ export async function onRequestPost(context: RequestContext) {
for (const urlResult of uploadUrlResults as PromiseFulfilledResult<string>[]) {
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");
}
Expand Down

0 comments on commit 2127574

Please sign in to comment.