Send transcoding jobs to coconut on report completion
This commit is contained in:
parent
c770e673fb
commit
6357de7e09
@ -21,6 +21,58 @@ export async function onRequestPost(context: RequestContext) {
|
||||
|
||||
if (!value) return jsonError("Report is missing", 500);
|
||||
|
||||
const coconutData = (await context.env.DATA.get(`coconutjob_${id}`, {
|
||||
type: "json",
|
||||
})) as {
|
||||
attachments: string[];
|
||||
token: string;
|
||||
} | null;
|
||||
|
||||
if (coconutData) {
|
||||
const coconutResponsePromises = [];
|
||||
|
||||
for (const attachment of coconutData.attachments)
|
||||
coconutResponsePromises.push(
|
||||
fetch("https://api.coconut.co/v2/jobs", {
|
||||
body: JSON.stringify({
|
||||
input: {
|
||||
bucket: "car-crushers",
|
||||
credentials: {
|
||||
access_key_id: context.env.R2_ACCESS_KEY,
|
||||
secret_access_key: context.env.R2_SECRET_KEY,
|
||||
},
|
||||
endpoint: `https://${context.env.R2_ZONE}.r2.cloudflarestorage.com`,
|
||||
key: `/t/${attachment}`,
|
||||
region: "us-east-1",
|
||||
service: "s3other",
|
||||
},
|
||||
outputs: {
|
||||
mp4: {
|
||||
path: `/${attachment}`,
|
||||
},
|
||||
},
|
||||
storage: {
|
||||
bucket: "car-crushers",
|
||||
credentials: {
|
||||
access_key_id: context.env.R2_ACCESS_KEY,
|
||||
secret_access_key: context.env.R2_SECRET_KEY,
|
||||
},
|
||||
endpoint: `https://${context.env.R2_ZONE}.r2.cloudflarestorage.com`,
|
||||
region: "us-east-1",
|
||||
service: "s3other",
|
||||
},
|
||||
}),
|
||||
headers: {
|
||||
authorization: `Basic ${btoa(`${context.env.COCONUT_API_KEY}:`)}`,
|
||||
"content-type": "application/json",
|
||||
},
|
||||
method: "POST",
|
||||
}),
|
||||
);
|
||||
|
||||
await Promise.allSettled(coconutResponsePromises);
|
||||
}
|
||||
|
||||
if (context.env.REPORTS_WEBHOOK) {
|
||||
await fetch(context.env.REPORTS_WEBHOOK, {
|
||||
body: JSON.stringify({
|
||||
|
Loading…
x
Reference in New Issue
Block a user