This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import { jsonBody } from '$lib/server/request-body.js';
|
||||
import { isHttpError, json } from '@sveltejs/kit';
|
||||
import { db } from '$lib/server/db/index.js';
|
||||
import { builtInPlans, parseBetaPlan } from '$lib/beta-plan.js';
|
||||
export function GET() {
|
||||
@@ -14,7 +15,7 @@ export function GET() {
|
||||
}
|
||||
export async function POST({ request }: { request: Request }) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const body = await jsonBody(request);
|
||||
if (typeof body.name !== 'string' || !body.name.trim() || body.name.length > 80)
|
||||
throw new Error('Preset name must be 1–80 characters');
|
||||
if (builtInPlans.some((p) => p.name === body.name.trim()))
|
||||
@@ -27,6 +28,7 @@ export async function POST({ request }: { request: Request }) {
|
||||
.run(body.name.trim(), JSON.stringify(plan));
|
||||
return json({ ok: true });
|
||||
} catch (error) {
|
||||
if (isHttpError(error, 413)) throw error;
|
||||
return json({ ok: false, error: (error as Error).message }, { status: 400 });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user