Only toLowerCase once

This commit is contained in:
Regalijan 2024-03-25 23:31:11 -04:00
parent 8bf794c2d2
commit e5bbde2bac
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

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