Fix ET strike endpoint
This commit is contained in:
parent
389c7070ed
commit
3e06541b30
@ -1,22 +1,35 @@
|
|||||||
import { jsonError } from "../../../common.js";
|
import { jsonError, jsonResponse } from "../../../common.js";
|
||||||
|
|
||||||
export async function onRequestPost(context: RequestContext) {
|
export async function onRequestPost(context: RequestContext) {
|
||||||
const { reason } = context.data.body;
|
const { reason, user } = context.data.body;
|
||||||
|
|
||||||
if (typeof reason !== "string") return jsonError("Invalid reason", 400);
|
if (typeof reason !== "string") return jsonError("Invalid reason", 400);
|
||||||
|
|
||||||
await context.env.D1.prepare(
|
if (
|
||||||
"INSERT INTO et_strikes (created_at, created_by, id, reason) VALUES (?, ?, ?, ?);",
|
typeof user !== "string" ||
|
||||||
|
user.length > 20 ||
|
||||||
|
user.length < 17 ||
|
||||||
|
user.match(/\D/)
|
||||||
)
|
)
|
||||||
.bind(
|
return jsonError("Invalid user id", 400);
|
||||||
Date.now(),
|
|
||||||
context.data.current_user.id,
|
const now = Date.now();
|
||||||
crypto.randomUUID().replaceAll("-", ""),
|
const id = crypto.randomUUID().replaceAll("-", "");
|
||||||
reason,
|
const actingUser = context.data.current_user.id;
|
||||||
)
|
|
||||||
|
await context.env.D1.prepare(
|
||||||
|
"INSERT INTO et_strikes (created_at, created_by, id, reason, user) VALUES (?, ?, ?, ?, ?);",
|
||||||
|
)
|
||||||
|
.bind(now, actingUser, id, reason, user)
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
return new Response(null, {
|
return jsonResponse(
|
||||||
status: 204,
|
JSON.stringify({
|
||||||
});
|
created_at: Date.now(),
|
||||||
|
created_by: context.data.current_user.id,
|
||||||
|
id,
|
||||||
|
reason,
|
||||||
|
user,
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user