Move userid validator to ban endpoint
This commit is contained in:
parent
debb8d9209
commit
75c38e9cc5
@ -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 &&
|
||||
|
@ -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 })
|
||||
|
Loading…
x
Reference in New Issue
Block a user