+server.ts
1import { json } from '@sveltejs/kit';
2import { commitStaged, commitAll } from '$lib/server/vcs';
3import { clearAll } from '$lib/server/review-store';
4import type { RequestHandler } from './$types.ts';
5
6export const POST: RequestHandler = async ({ request }) => {
7 try {
8 const body = await request.json();
9 const { message, mode } = body;
10
11 if (!message?.trim()) {
12 return json({ error: 'Commit message is required' }, { status: 400 });
13 }
14
15 let hash: string;
16 if (mode === 'approved') {
17 // Commit only staged (approved) files
18 hash = await commitStaged(message.trim());
19 } else {
20 // Commit all changes
21 hash = await commitAll(message.trim());
22 }
23
24 clearAll();
25 return json({ success: true, hash });
26 } catch (err) {
27 return json({ error: String(err) }, { status: 500 });
28 }
29};