Greatly reduce repeated code
This commit is contained in:
@ -1,22 +1,14 @@
|
||||
import { jsonError } from "../../common.js";
|
||||
|
||||
export async function onRequestPost(context: RequestContext) {
|
||||
const { active } = context.data.body;
|
||||
const { permissions } = context.data.current_user;
|
||||
|
||||
if (!(permissions & (1 << 0)) && !(permissions & (1 << 11)))
|
||||
return new Response('{"error":"Forbidden"}', {
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
status: 403,
|
||||
});
|
||||
return jsonError("Forbidden", 403);
|
||||
|
||||
if (typeof active !== "boolean")
|
||||
return new Response('{"error":"Active property must be a boolean"}', {
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
status: 400,
|
||||
});
|
||||
return jsonError("Active property must be a boolean", 400);
|
||||
|
||||
if (active) {
|
||||
await context.env.DATA.delete("appeal_disabled");
|
||||
|
Reference in New Issue
Block a user