Handle coconut's requirement for file extensions
This commit is contained in:
@ -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",
|
||||
|
Reference in New Issue
Block a user