add report admin panel
All checks were successful
delpoy / build-and-deploy (push) Successful in 53s

This commit is contained in:
2023-09-29 02:08:34 +02:00
parent 37c230575d
commit 722026c938
19 changed files with 423 additions and 26 deletions

View File

@ -17,14 +17,15 @@ export const POST = (async ({ request, url }) => {
subject: data.reason,
body: null,
draft: true,
url_id: crypto.randomBytes(18).toString('hex'),
status: 'none',
url_hash: crypto.randomBytes(18).toString('hex'),
completed: false,
reporter_user_id: reporter.id,
reported_user_id: reported.id
reporter_id: reporter.id,
reported_id: reported.id
});
return new Response(
JSON.stringify({ url: `${url.toString().replace(/\/$/, '')}/${report.url_id}` }),
JSON.stringify({ url: `${url.toString().replace(/\/$/, '')}/${report.url_hash}` }),
{
status: 201
}

View File

@ -5,7 +5,7 @@ import { env } from '$env/dynamic/public';
export const load: PageServerLoad = async ({ params }) => {
const report = await Report.findOne({
where: { url_id: params.url_id },
where: { url_hash: params.url_hash },
include: [
{ model: User, as: 'reporter' },
{ model: User, as: 'reported' }
@ -16,7 +16,7 @@ export const load: PageServerLoad = async ({ params }) => {
return {
draft: report.draft,
completed: report.completed,
status: report.status,
reason: report.subject,
reporter: {
name: report.reporter.username

View File

@ -22,7 +22,7 @@
on:submit={() => (data.draft = false)}
/>
</div>
{:else if data.completed}
{:else if data.status === 'reviewed'}
<ReportCompleted />
{:else}
<div class="col-[1] row-[1]" transition:fly={{ x: 200, duration: 300 }}>

View File

@ -2,7 +2,7 @@ import type { RequestHandler } from '@sveltejs/kit';
import { Report } from '$lib/server/database';
export const POST = (async ({ params }) => {
const report = await Report.findOne({ where: { url_id: params.url_id } });
const report = await Report.findOne({ where: { url_hash: params.url_hash } });
if (report == null) return new Response(null, { status: 400 });

View File

@ -9,7 +9,7 @@
export let reason: string;
async function submitReport() {
await fetch(`${env.PUBLIC_BASE_PATH}/report/${$page.params.url_id}`, {
await fetch(`${env.PUBLIC_BASE_PATH}/report/${$page.params.url_hash}`, {
method: 'POST'
});
}