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) {
|
if (coconutData) {
|
||||||
const responsePromises = [];
|
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) {
|
for (const attachment of coconutData.attachments) {
|
||||||
const token = crypto.randomUUID();
|
const token = crypto.randomUUID();
|
||||||
|
const objectMeta = await context.env.R2.head(attachment);
|
||||||
|
|
||||||
|
if (!objectMeta) continue;
|
||||||
|
|
||||||
responsePromises.push(
|
responsePromises.push(
|
||||||
fetch("https://api.coconut.co/v2/jobs", {
|
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,
|
secret_access_key: context.env.R2_SECRET_KEY,
|
||||||
},
|
},
|
||||||
endpoint: `https://${context.env.R2_ZONE}.r2.cloudflarestorage.com`,
|
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",
|
region: "us-east-1",
|
||||||
service: "s3other",
|
service: "s3other",
|
||||||
},
|
},
|
||||||
notification: {
|
notification: {
|
||||||
params: {
|
params: {
|
||||||
attachment: attachment,
|
attachment,
|
||||||
token,
|
token,
|
||||||
},
|
},
|
||||||
type: "http",
|
type: "http",
|
||||||
|
@ -163,7 +163,9 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
uploadUrlPromises.push(
|
uploadUrlPromises.push(
|
||||||
upload(
|
upload(
|
||||||
context.env,
|
context.env,
|
||||||
`${["mp4", "m4v", "webm"].includes(fileExten) ? "" : "t/"}${fileUploadKey}`,
|
["mp4", "m4v", "webm"].includes(fileExten)
|
||||||
|
? fileUploadKey
|
||||||
|
: `t/${fileUploadKey}.${fileExten}`,
|
||||||
file.size,
|
file.size,
|
||||||
fileExten,
|
fileExten,
|
||||||
),
|
),
|
||||||
@ -206,7 +208,11 @@ 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);
|
||||||
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(
|
await context.env.DATA.put(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user