Move userid validator to ban endpoint
This commit is contained in:
parent
debb8d9209
commit
75c38e9cc5
@ -12,16 +12,22 @@ export async function onRequestPost(context: RequestContext) {
|
|||||||
const { body } = context.data;
|
const { body } = context.data;
|
||||||
const id = context.params.id as string;
|
const id = context.params.id as string;
|
||||||
|
|
||||||
if (id.search(/^\d{16,19}$/) === -1)
|
|
||||||
return new Response('{"error":"Invalid target id"}', {
|
|
||||||
headers: {
|
|
||||||
"content-type": "application/json",
|
|
||||||
},
|
|
||||||
status: 400,
|
|
||||||
});
|
|
||||||
|
|
||||||
context.data.targetId = 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: 404,
|
||||||
|
});
|
||||||
|
|
||||||
|
context.data.appeal = keyWithMeta;
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
body.feedback &&
|
body.feedback &&
|
||||||
(typeof body.feedback !== "string" || body.feedback.length > 512)
|
(typeof body.feedback !== "string" || body.feedback.length > 512)
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
export async function onRequestPost(context: RequestContext) {
|
export async function onRequestPost(context: RequestContext) {
|
||||||
const { current_user: currentUser } = context.data;
|
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(
|
await context.env.DATA.put(
|
||||||
`appealban_${context.data.targetId}`,
|
`appealban_${context.data.targetId}`,
|
||||||
JSON.stringify({ moderator: currentUser.id })
|
JSON.stringify({ moderator: currentUser.id })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user