From ffe70100ac4017c0f8c512e0f75ed1f9ca19f232 Mon Sep 17 00:00:00 2001 From: regalijan Date: Thu, 19 Oct 2023 16:51:16 -0400 Subject: [PATCH] Add appeal submit status endpoint --- functions/api/appeals/submit.ts | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/functions/api/appeals/submit.ts b/functions/api/appeals/submit.ts index a7db0eb..f3bcbd0 100644 --- a/functions/api/appeals/submit.ts +++ b/functions/api/appeals/submit.ts @@ -1,7 +1,28 @@ -import { jsonError } from "../../common.js"; +import { jsonError, jsonResponse } from "../../common.js"; + +export async function onRequestGet(context: RequestContext) { + const { current_user: currentUser } = context.data; + + if ( + !currentUser.email || + (await context.env.DATA.get("appeal_disabled")) || + (await context.env.D1.prepare( + "SELECT id FROM appeals WHERE open = 1 AND user = ?;", + ) + .bind(currentUser.id) + .first()) || + (await context.env.DATA.get(`blockedappeal_${currentUser.id}`)) + ) + return jsonResponse('{"can_appeal":false}'); + + return jsonResponse('{"can_appeal":true}'); +} export async function onRequestPost(context: RequestContext) { - const { learned, whyBanned, whyUnban } = context.data.body; + if (await context.env.DATA.get("appeal_disabled")) + return jsonError("Appeals are disabled", 403); + + const { learned, senderTokenId, whyBanned, whyUnban } = context.data.body; if ( typeof learned !== "string" || @@ -58,6 +79,7 @@ export async function onRequestPost(context: RequestContext) { JSON.stringify({ ban_reason: whyBanned, created_at: Date.now(), + fcm_token: typeof senderTokenId === "string" ? senderTokenId : undefined, learned, id: appealId, reason_for_unban: whyUnban,