Permalink
Newer
100644
106 lines (93 sloc)
2.6 KB
3
export async function onRequestPost(context: RequestContext) {
4
const { learned, whyBanned, whyUnban } = context.data.body;
5
6
if (
7
typeof learned !== "string" ||
8
typeof whyBanned !== "string" ||
9
typeof whyUnban !== "string" ||
10
!learned.length ||
11
learned.length > 2000 ||
12
!whyBanned.length ||
13
whyBanned.length > 500 ||
14
!whyUnban.length ||
15
whyUnban.length > 2000
16
)
21
if (!currentUser.email) return jsonError("No email for this session", 403);
22
23
const existingAppeals = await context.env.DATA.list({
24
prefix: `appeal_${currentUser.id}`,
25
});
26
const existingBlockedAppeal = await context.env.DATA.get(
39
await context.env.D1.prepare("SELECT * FROM appeal_bans WHERE user = ?;")
40
.bind(currentUser.id)
41
.first()
43
await context.env.DATA.put(`blockedappeal_${currentUser.id}`, "1", {
44
metadata: { email: currentUser.email },
45
});
46
47
return new Response(null, {
48
status: 204,
49
});
50
}
51
52
const appealId = `${currentUser.id}${Date.now()}${crypto
53
.randomUUID()
54
.replaceAll("-", "")}`;
55
56
await context.env.DATA.put(
57
`appeal_${appealId}`,
58
JSON.stringify({
64
user: {
65
email: currentUser.email,
66
id: currentUser.id,
67
username: currentUser.username,
68
},
75
await context.env.D1.prepare(
76
"INSERT INTO appeals (created_at, id, open, user) VALUES (?, ?, ?, ?)",
77
)
78
.bind(Date.now(), appealId, 1, currentUser.id)
79
.run();
80
81
await fetch(context.env.APPEALS_WEBHOOK, {
82
body: JSON.stringify({
83
embeds: [
84
{
85
title: "Appeal Submitted",
86
color: 3756250,
87
description: `View this appeal at https://carcrushers.cc/mod-queue?id=${appealId}&type=appeal`,
88
fields: [
89
{
90
name: "Submitter",