20 lines
896 B
TypeScript
20 lines
896 B
TypeScript
import { json } from '@sveltejs/kit';
|
|
import { queueHostOperation } from '$lib/server/hosts/index.js';
|
|
import { hostApiError, objectBody, requireManagementOrigin } from '$lib/server/hosts/http.js';
|
|
export async function POST({ request, params }: { request: Request; params: { id: string } }) {
|
|
requireManagementOrigin(request);
|
|
try {
|
|
const body = await objectBody(request);
|
|
if (
|
|
body.kind !== 'runtime.pull' ||
|
|
typeof body.image !== 'string' ||
|
|
!/^[a-zA-Z0-9][a-zA-Z0-9./_:@-]{0,511}$/.test(body.image)
|
|
)
|
|
throw new Error('Provide a runtime.pull request and a valid container image.');
|
|
const operation = queueHostOperation(params.id, 'runtime.pull', { image: body.image });
|
|
return json({ operationId: operation.id }, { status: 202 });
|
|
} catch (cause) {
|
|
return hostApiError(cause);
|
|
}
|
|
}
|