55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
export async function onRequestPost(context: RequestContext) {
|
|
const { id } = context.data.body;
|
|
|
|
if (!id)
|
|
return new Response('{"error":"No ID provided"}', {
|
|
headers: {
|
|
"content-type": "application/json",
|
|
},
|
|
status: 400,
|
|
});
|
|
|
|
const userId = await context.env.DATA.get(`reportprocessing_${id}`);
|
|
|
|
if (!userId || userId !== context.data.current_user.id)
|
|
return new Response('{"error":"No report with that ID is processing"}', {
|
|
headers: {
|
|
"content-type": "application/json",
|
|
},
|
|
status: 404,
|
|
});
|
|
|
|
await context.env.DATA.delete(`reportprocessing_${id}`);
|
|
|
|
const {
|
|
metadata,
|
|
value,
|
|
}: KVNamespaceGetWithMetadataResult<string, { [k: string]: any }> =
|
|
await context.env.DATA.getWithMetadata(`report_${id}`);
|
|
|
|
delete metadata?.p;
|
|
await context.env.DATA.put(`report_${id}`, value as string, { metadata });
|
|
|
|
if (context.env.REPORTS_WEBHOOK) {
|
|
await fetch(context.env.REPORTS_WEBHOOK, {
|
|
body: JSON.stringify({
|
|
embeds: [
|
|
{
|
|
title: "Report Submitted",
|
|
color: 3756250,
|
|
description: `View this report at https://carcrushers.cc/mod-queue?id=${id}&type=game-report`,
|
|
},
|
|
],
|
|
}),
|
|
headers: {
|
|
"content-type": "application/json",
|
|
},
|
|
method: "POST",
|
|
});
|
|
}
|
|
|
|
return new Response(null, {
|
|
status: 204,
|
|
});
|
|
}
|