Move userid validator to ban endpoint

This commit is contained in:
regalijan 2023-10-19 16:49:14 -04:00
parent debb8d9209
commit 75c38e9cc5
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520
2 changed files with 22 additions and 8 deletions

View File

@ -12,15 +12,21 @@ export async function onRequestPost(context: RequestContext) {
const { body } = context.data;
const id = context.params.id as string;
if (id.search(/^\d{16,19}$/) === -1)
return new Response('{"error":"Invalid target id"}', {
context.data.targetId = id;
if (!new URL(context.request.url).pathname.endsWith("/ban")) {
const keyWithMeta = await context.env.DATA.getWithMetadata(`appeal_${id}`);
if (!keyWithMeta.value)
return new Response('{"error":"No appeal with that ID exists"}', {
headers: {
"content-type": "application/json",
},
status: 400,
status: 404,
});
context.data.targetId = id;
context.data.appeal = keyWithMeta;
}
if (
body.feedback &&

View File

@ -1,6 +1,14 @@
export async function onRequestPost(context: RequestContext) {
const { current_user: currentUser } = context.data;
if (context.data.targetId.search(/^\d{16,19}$/) === -1)
return new Response('{"error":"Invalid target id"}', {
headers: {
"content-type": "application/json",
},
status: 400,
});
await context.env.DATA.put(
`appealban_${context.data.targetId}`,
JSON.stringify({ moderator: currentUser.id })