Skip to content
Permalink
05a0d192c3
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
44 lines (37 sloc) 1.1 KB
export async function onRequestPost(context: RequestContext) {
const { body } = context.data;
if (
!Array.isArray(body) ||
body.find((attachment) => typeof attachment !== "string")
)
return new Response(
'{"error":"Request body must be an array of strings"}',
{
headers: {
"content-type": "application/json",
},
status: 400,
},
);
if (body.length > 3)
return new Response('{"error":"Too many video ids"}', {
headers: {
"content-type": "application/json",
},
status: 400,
});
const kvPromises = [];
for (const attachment of body)
kvPromises.push(context.env.DATA.get(`videoprocessing_${attachment}`));
const kvResults = await Promise.allSettled(kvPromises);
if (kvResults.find((result) => result.status === "rejected"))
return new Response('{"error":"Failed to check status of attachments"}', {
headers: {
"content-type": "application/json",
},
status: 500,
});
return new Response(null, {
status: kvResults.find((result) => result !== null) ? 409 : 204,
});
}