19 lines
1.0 KiB
TypeScript
19 lines
1.0 KiB
TypeScript
import { error, json } from '@sveltejs/kit';
|
|
import { listHostOperationHistory } from '$lib/server/hosts/index.js';
|
|
import { requireManagementOrigin } from '$lib/server/hosts/http.js';
|
|
import { hostOperationScope, isHostOperationFilter } from '$lib/hosts.js';
|
|
|
|
export function GET({ request }: { request: Request }) {
|
|
requireManagementOrigin(request);
|
|
const params = new URL(request.url).searchParams;
|
|
const page = Number(params.get('page') ?? '1');
|
|
const filter = params.get('filter') ?? 'important';
|
|
if (!Number.isSafeInteger(page) || page < 1) error(400, 'Invalid operation history page.');
|
|
if (!isHostOperationFilter(filter)) error(400, 'Invalid operation history filter.');
|
|
const scope = hostOperationScope(params);
|
|
for (const key of ['host', 'server', 'operation'] as const) {
|
|
if (params.has(key) && params.get(key) !== scope[key]) error(400, 'Invalid operation history scope.');
|
|
}
|
|
return json(listHostOperationHistory(page, filter, scope), { headers: { 'Cache-Control': 'no-store' } });
|
|
}
|