Greatly reduce repeated code
This commit is contained in:
@ -1,13 +1,9 @@
|
||||
import { jsonError } from "../../common.js";
|
||||
|
||||
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,
|
||||
});
|
||||
if (!id) return jsonError("No ID provided", 400);
|
||||
|
||||
const user = await context.env.DATA.get(`reportprocessing_${id}`);
|
||||
|
||||
@ -17,24 +13,13 @@ export async function onRequestPost(context: RequestContext) {
|
||||
? user !== context.data.current_user.id
|
||||
: user !== context.request.headers.get("CF-Connecting-IP"))
|
||||
)
|
||||
return new Response('{"error":"No report with that ID is processing"}', {
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
status: 404,
|
||||
});
|
||||
return jsonError("No report with that ID is processing", 404);
|
||||
|
||||
await context.env.DATA.delete(`reportprocessing_${id}`);
|
||||
|
||||
const value = await context.env.DATA.get(`report_${id}`);
|
||||
|
||||
if (!value)
|
||||
return new Response('{"error":"Report is missing"}', {
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
status: 500,
|
||||
});
|
||||
if (!value) return jsonError("Report is missing", 500);
|
||||
|
||||
if (context.env.REPORTS_WEBHOOK) {
|
||||
await fetch(context.env.REPORTS_WEBHOOK, {
|
||||
|
Reference in New Issue
Block a user