18 lines
643 B
TypeScript
18 lines
643 B
TypeScript
import { json } from '@sveltejs/kit';
|
|
import { listBlueprints, saveBlueprint } from '$lib/server/fleet/launch-recipes.js';
|
|
|
|
export function GET() {
|
|
return json({ blueprints: listBlueprints() });
|
|
}
|
|
|
|
export async function POST({ request }: { request: Request }) {
|
|
try {
|
|
const body = await request.json();
|
|
if (!body || typeof body !== 'object' || Array.isArray(body))
|
|
throw new Error('Provide a collection name and a launch recipe.');
|
|
return json({ blueprint: saveBlueprint(body) }, { status: 201 });
|
|
} catch (err) {
|
|
return json({ error: (err as Error).message }, { status: 400 });
|
|
}
|
|
}
|