From e5bbde2bac55e739313d2298b182f10f0026d1c7 Mon Sep 17 00:00:00 2001
From: Regalijan <r@regalijan.com>
Date: Mon, 25 Mar 2024 23:31:11 -0400
Subject: [PATCH] Only toLowerCase once

---
 functions/api/reports/submit.ts | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/functions/api/reports/submit.ts b/functions/api/reports/submit.ts
index e297228..c9422ce 100644
--- a/functions/api/reports/submit.ts
+++ b/functions/api/reports/submit.ts
@@ -140,16 +140,14 @@ export async function onRequestPost(context: RequestContext) {
   const filesToProcess = [];
 
   for (const file of files) {
-    const fileParts = file.name.split(".");
+    const fileParts = file.name.split(".").toLowerCase();
     let fileExten = fileParts.at(-1);
 
-    if (fileExten.toLowerCase() === "mov") fileExten = "mp4";
+    if (fileExten === "mov") fileExten = "mp4";
 
     if (
       fileParts.length < 2 ||
-      !["mkv", "mp4", "wmv", "m4v", "gif", "webm"].includes(
-        fileExten.toLowerCase(),
-      )
+      !["mkv", "mp4", "wmv", "m4v", "gif", "webm"].includes(fileExten)
     )
       return jsonError(
         `File ${file.name} cannot be uploaded as it is unsupported`,
@@ -165,7 +163,7 @@ export async function onRequestPost(context: RequestContext) {
     uploadUrlPromises.push(
       upload(
         context.env,
-        `${["mp4", "m4v", "webm"].includes(fileExten.toLowerCase()) ? "" : "t/"}${fileUploadKey}`,
+        `${["mp4", "m4v", "webm"].includes(fileExten) ? "" : "t/"}${fileUploadKey}`,
         file.size,
         fileExten,
       ),