use zod schemes for validation
All checks were successful
delpoy / build-and-deploy (push) Successful in 53s

This commit is contained in:
2024-10-19 18:07:11 +02:00
parent ac38540424
commit c2c1660064
12 changed files with 193 additions and 153 deletions

View File

@ -3,14 +3,17 @@ import { Report, User } from '$lib/server/database';
import * as crypto from 'crypto';
import { env as public_env } from '$env/dynamic/public';
import { env } from '$env/dynamic/private';
import { ReportAddSchema } from './schema';
export const POST = (async ({ request, url }) => {
if (env.REPORT_SECRET && url.searchParams.get('secret') !== env.REPORT_SECRET)
return new Response(null, { status: 401 });
const data: { reporter: string; reported: string | null; reason: string } = await request.json();
if (data.reporter == null || data.reason == null) return new Response(null, { status: 400 });
const parseResult = await ReportAddSchema.safeParseAsync(await request.json());
if (!parseResult.success) {
return new Response(null, { status: 400 });
}
const data = parseResult.data;
const reporter = await User.findOne({ where: { uuid: data.reporter } });
const reported = data.reported

View File

@ -0,0 +1,7 @@
import { z } from 'zod';
export const ReportAddSchema = z.object({
reporter: z.string(),
reported: z.string().nullish(),
reason: z.string()
});