Handle coconut's requirement for file extensions
This commit is contained in:
parent
2f335cf57a
commit
c06375ea5c
@ -29,9 +29,21 @@ export async function onRequestPost(context: RequestContext) {
|
||||
|
||||
if (coconutData) {
|
||||
const responsePromises = [];
|
||||
const contentTypes: { [k: string]: string } = {
|
||||
gif: "image/gif",
|
||||
m4v: "video/x-m4v",
|
||||
mkv: "video/x-matroska",
|
||||
mov: "video/mp4",
|
||||
mp4: "video/mp4",
|
||||
webm: "video/webm",
|
||||
wmv: "video/x-ms-wmv",
|
||||
};
|
||||
|
||||
for (const attachment of coconutData.attachments) {
|
||||
const token = crypto.randomUUID();
|
||||
const objectMeta = await context.env.R2.head(attachment);
|
||||
|
||||
if (!objectMeta) continue;
|
||||
|
||||
responsePromises.push(
|
||||
fetch("https://api.coconut.co/v2/jobs", {
|
||||
@ -43,13 +55,13 @@ export async function onRequestPost(context: RequestContext) {
|
||||
secret_access_key: context.env.R2_SECRET_KEY,
|
||||
},
|
||||
endpoint: `https://${context.env.R2_ZONE}.r2.cloudflarestorage.com`,
|
||||
key: `/t/${attachment}`,
|
||||
key: `/t/${attachment}.${contentTypes[objectMeta.httpMetadata?.contentType as string]}`,
|
||||
region: "us-east-1",
|
||||
service: "s3other",
|
||||
},
|
||||
notification: {
|
||||
params: {
|
||||
attachment: attachment,
|
||||
attachment,
|
||||
token,
|
||||
},
|
||||
type: "http",
|
||||
|
@ -163,7 +163,9 @@ export async function onRequestPost(context: RequestContext) {
|
||||
uploadUrlPromises.push(
|
||||
upload(
|
||||
context.env,
|
||||
`${["mp4", "m4v", "webm"].includes(fileExten) ? "" : "t/"}${fileUploadKey}`,
|
||||
["mp4", "m4v", "webm"].includes(fileExten)
|
||||
? fileUploadKey
|
||||
: `t/${fileUploadKey}.${fileExten}`,
|
||||
file.size,
|
||||
fileExten,
|
||||
),
|
||||
@ -206,7 +208,11 @@ export async function onRequestPost(context: RequestContext) {
|
||||
|
||||
for (const urlResult of uploadUrlResults as PromiseFulfilledResult<string>[]) {
|
||||
uploadUrls.push(urlResult.value);
|
||||
attachments.push(new URL(urlResult.value).pathname.replace(/^\/?t?\//, ""));
|
||||
attachments.push(
|
||||
new URL(urlResult.value).pathname
|
||||
.replace(/^\/?t?\//, "")
|
||||
.replace(/\.w*$/, ""),
|
||||
);
|
||||
}
|
||||
|
||||
await context.env.DATA.put(
|
||||
|
Loading…
x
Reference in New Issue
Block a user