Add direct submission support

This commit is contained in:
regalijan 2023-10-19 16:49:43 -04:00
parent 6503af20f3
commit 7c0fec574a
Signed by: regalijan
GPG Key ID: 5D4196DA269EF520

View File

@ -10,7 +10,7 @@ function errorResponse(error: string, status: number): Response {
} }
export async function onRequestPost(context: RequestContext) { export async function onRequestPost(context: RequestContext) {
const { filename, filesize, turnstileResponse, usernames } = const { actions, bypass, filename, filesize, turnstileResponse, usernames } =
context.data.body; context.data.body;
if (!context.data.current_user) { if (!context.data.current_user) {
@ -36,6 +36,12 @@ export async function onRequestPost(context: RequestContext) {
if (!success) return errorResponse("Captcha test failed", 403); if (!success) return errorResponse("Captcha test failed", 403);
} }
if (bypass && !(context.data.current_user?.permissions & (1 << 5)))
return errorResponse("Bypass directive cannot be used", 403);
if (typeof bypass !== "boolean")
return errorResponse("Bypass must be a boolean", 400);
if (!Array.isArray(usernames)) if (!Array.isArray(usernames))
return errorResponse("Usernames must be type of array", 400); return errorResponse("Usernames must be type of array", 400);
@ -164,6 +170,7 @@ export async function onRequestPost(context: RequestContext) {
["mkv", "mov", "wmv"].includes(fileExt.toLowerCase()) ? "mp4" : fileExt ["mkv", "mov", "wmv"].includes(fileExt.toLowerCase()) ? "mp4" : fileExt
}`, }`,
id: reportId, id: reportId,
open: !bypass,
user: currentUser user: currentUser
? { ? {
discriminator: currentUser.discriminator, discriminator: currentUser.discriminator,
@ -181,7 +188,7 @@ export async function onRequestPost(context: RequestContext) {
await context.env.D1.prepare( await context.env.D1.prepare(
"INSERT INTO reports (created_at, id, open, user) VALUES (?, ?, ?, ?);" "INSERT INTO reports (created_at, id, open, user) VALUES (?, ?, ?, ?);"
) )
.bind(Date.now(), reportId, 1, currentUser?.id || null) .bind(Date.now(), reportId, Number(!bypass), currentUser?.id || null)
.run(); .run();
} catch {} } catch {}