Add appeal submit status endpoint

This commit is contained in:
regalijan 2023-10-19 16:51:16 -04:00
parent b6c051f3cb
commit ffe70100ac
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -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,