Fix file extension handling
This commit is contained in:
parent
91ff428d9a
commit
2127574a33
@ -142,11 +142,14 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
const uploadUrlPromises: Promise<string>[] = [];
|
const uploadUrlPromises: Promise<string>[] = [];
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const filePartes = file.name.split(".");
|
const fileParts = file.name.split(".");
|
||||||
let fileExten = filePartes.at(-1);
|
let fileExten = fileParts.at(-1);
|
||||||
|
|
||||||
|
if (fileExten.toLowerCase() === "mov")
|
||||||
|
fileExten = "mp4"
|
||||||
|
|
||||||
if (
|
if (
|
||||||
filePartes.length < 2 ||
|
fileParts.length < 2 ||
|
||||||
![
|
![
|
||||||
"mkv",
|
"mkv",
|
||||||
"mp4",
|
"mp4",
|
||||||
@ -161,7 +164,6 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
"heif",
|
"heif",
|
||||||
"heic",
|
"heic",
|
||||||
"webp",
|
"webp",
|
||||||
"mov",
|
|
||||||
].includes(fileExten.toLowerCase())
|
].includes(fileExten.toLowerCase())
|
||||||
)
|
)
|
||||||
return errorResponse(
|
return errorResponse(
|
||||||
@ -209,15 +211,13 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
for (const urlResult of uploadUrlResults as PromiseFulfilledResult<string>[]) {
|
for (const urlResult of uploadUrlResults as PromiseFulfilledResult<string>[]) {
|
||||||
uploadUrls.push(urlResult.value);
|
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();
|
const extension = (url.split(".").at(-1) as string).toLowerCase();
|
||||||
|
|
||||||
if (["mkv", "mov", "wmv"].includes(extension)) {
|
if (["mkv", "wmv"].includes(extension)) {
|
||||||
// These are merely glorified mp4 containers
|
await context.env.DATA.put(`videoprocessing_${url.replace(`.${extension}`, ".mp4")}`, "1", {
|
||||||
if (extension !== "mov")
|
expirationTtl: 600,
|
||||||
await context.env.DATA.put(`videoprocessing_${url}.${extension}`, "1", {
|
});
|
||||||
expirationTtl: 600,
|
|
||||||
});
|
|
||||||
|
|
||||||
url = url.replace(`.${extension}`, ".mp4");
|
url = url.replace(`.${extension}`, ".mp4");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user