Skip to content
Permalink
e00b7e8c55
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
51 lines (37 sloc) 1.41 KB
import { jsonError } from "../../../common.js";
export async function onRequestPost(context: RequestContext) {
const { pathname } = new URL(context.request.url);
// Fix weirdo routing issue
if (pathname.endsWith("/submit") || pathname.endsWith("/toggle"))
return await context.next();
const { permissions } = context.data.current_user;
if (!(permissions & (1 << 0)) && !(permissions & (1 << 11)))
return jsonError("Forbidden", 403);
if (pathname.endsWith("/bans")) return await context.next();
const { body } = context.data;
const id = context.params.id as string;
context.data.targetId = id;
if (!pathname.endsWith("/ban")) {
const appeal: Record<string, any> | null = await context.env.D1.prepare(
"SELECT * FROM appeals WHERE id = ?;",
)
.bind(id)
.first();
if (!appeal) return jsonError("No appeal with that ID exists", 404);
appeal.user = JSON.parse(appeal.user);
context.data.appeal = appeal;
const pushNotificationData = await context.env.D1.prepare(
"SELECT token FROM push_notifications WHERE event_id = ? AND event_type = 'appeal';",
)
.bind(id)
.first();
if (pushNotificationData)
context.data.fcm_token = pushNotificationData.token;
}
if (
body.feedback &&
(typeof body.feedback !== "string" || body.feedback.length > 512)
)
return jsonError("Invalid feedback", 400);
return await context.next();
}