Greatly reduce repeated code
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import { jsonError } from "../../common.js";
|
||||
|
||||
export async function onRequestPost(context: RequestContext) {
|
||||
const { learned, whyBanned, whyUnban } = context.data.body;
|
||||
|
||||
@ -12,25 +14,11 @@ export async function onRequestPost(context: RequestContext) {
|
||||
!whyUnban.length ||
|
||||
whyUnban.length > 2000
|
||||
)
|
||||
return new Response(
|
||||
'{"error":"One or more fields are missing or invalid"}',
|
||||
{
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
status: 400,
|
||||
},
|
||||
);
|
||||
return jsonError("One or more fields are missing or invalid", 400);
|
||||
|
||||
const { current_user: currentUser } = context.data;
|
||||
|
||||
if (!currentUser.email)
|
||||
return new Response('{"error":"No email for this session"}', {
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
status: 403,
|
||||
});
|
||||
if (!currentUser.email) return jsonError("No email for this session", 403);
|
||||
|
||||
const existingAppeals = await context.env.DATA.list({
|
||||
prefix: `appeal_${currentUser.id}`,
|
||||
@ -45,12 +33,7 @@ export async function onRequestPost(context: RequestContext) {
|
||||
(appeal) => (appeal.metadata as { [k: string]: any })?.open,
|
||||
)
|
||||
)
|
||||
return new Response('{"error":"Appeal already submitted"}', {
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
status: 403,
|
||||
});
|
||||
return jsonError("Appeal already submitted", 403);
|
||||
|
||||
if (
|
||||
await context.env.D1.prepare("SELECT * FROM appeal_bans WHERE user = ?;")
|
||||
|
Reference in New Issue
Block a user