redirect to root on unknown report hash

This commit is contained in:
bytedream 2024-11-29 00:00:50 +01:00
parent 58d39921cb
commit dc86dceb2f
3 changed files with 7 additions and 48 deletions

View File

@ -1,5 +0,0 @@
<div class="h-screen flex justify-center items-center">
<h1 class="text-4xl">
Reports können nur ingame mittels des <code>/report</code> Befehls erstellt werden
</h1>
</div>

View File

@ -0,0 +1,7 @@
import type { PageLoad } from './$types';
import { redirect } from '@sveltejs/kit';
import { env } from '$env/dynamic/public';
export const load: PageLoad = async () => {
throw redirect(302, `${env.PUBLIC_BASE_PATH}/`);
};

View File

@ -1,43 +0,0 @@
import type { RequestHandler } from '@sveltejs/kit';
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';
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 reporter = await User.findOne({ where: { uuid: data.reporter } });
const reported = data.reported
? await User.findOne({ where: { uuid: data.reported } })
: undefined;
if (reporter == null || reported === null) return new Response(null, { status: 400 });
const report = await Report.create({
subject: data.reason,
body: null,
draft: true,
status: 'none',
url_hash: crypto.randomBytes(18).toString('hex'),
completed: false,
reporter_id: reporter.id,
reported_id: reported?.id || null
});
return new Response(
JSON.stringify({
url: `${url.protocol}//${url.host}${public_env.PUBLIC_BASE_PATH || ''}/report/${
report.url_hash
}`
}),
{
status: 201
}
);
}) satisfies RequestHandler;