Files
website/src/routes/feedback/+server.ts
bytedream 55798fd294
All checks were successful
delpoy / build-and-deploy (push) Successful in 1m5s
add public feedback/contact option
2024-11-30 03:00:46 +01:00

21 lines
638 B
TypeScript

import type { RequestHandler } from '@sveltejs/kit';
import { Feedback } from '$lib/server/database';
import { FeedbackSubmitSchema } from './schema';
import crypto from 'crypto';
export const POST = (async ({ request }) => {
const parseResult = await FeedbackSubmitSchema.safeParseAsync(await request.json());
if (!parseResult.success) {
return new Response(null, { status: 400 });
}
const data = parseResult.data;
await Feedback.create({
event: `website-${data.type}`,
content: data.content,
url_hash: crypto.randomBytes(18).toString('hex')
});
return new Response(null, { status: 200 });
}) satisfies RequestHandler;