use zod schemes for validation
All checks were successful
delpoy / build-and-deploy (push) Successful in 53s
All checks were successful
delpoy / build-and-deploy (push) Successful in 53s
This commit is contained in:
@ -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
|
||||
|
7
src/routes/api/report/schema.ts
Normal file
7
src/routes/api/report/schema.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const ReportAddSchema = z.object({
|
||||
reporter: z.string(),
|
||||
reported: z.string().nullish(),
|
||||
reason: z.string()
|
||||
});
|
Reference in New Issue
Block a user