20 lines
828 B
TypeScript
20 lines
828 B
TypeScript
import { jsonBody } from '$lib/server/request-body.js';
|
|
import { isHttpError, json } from '@sveltejs/kit';
|
|
import { previewCreation } from '$lib/server/provisioning/index.js';
|
|
|
|
export async function POST({ request }: { request: Request }) {
|
|
try {
|
|
const body = await jsonBody(request);
|
|
if (!body || typeof body !== 'object' || Array.isArray(body))
|
|
throw new Error('Provide a launch selection.');
|
|
if (body.blueprintId !== undefined)
|
|
throw new Error(
|
|
'Collections use target counts. Use /api/deployment-collections/preview to preview only missing servers.'
|
|
);
|
|
return json(previewCreation(body));
|
|
} catch (err) {
|
|
if (isHttpError(err, 413)) throw err;
|
|
return json({ error: (err as Error).message }, { status: 400 });
|
|
}
|
|
}
|