add public feedback/contact option
All checks were successful
delpoy / build-and-deploy (push) Successful in 1m5s
All checks were successful
delpoy / build-and-deploy (push) Successful in 1m5s
This commit is contained in:
20
src/routes/feedback/+server.ts
Normal file
20
src/routes/feedback/+server.ts
Normal file
@ -0,0 +1,20 @@
|
||||
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;
|
Reference in New Issue
Block a user