Add host capacity sample viewer with filtering and pagination
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { error, json } from '@sveltejs/kit';
|
||||
import { getHost } from '$lib/server/hosts/index.js';
|
||||
import { requireManagementOrigin } from '$lib/server/hosts/http.js';
|
||||
import { capacitySamples } from '$lib/server/hosts/calibration.js';
|
||||
|
||||
export function GET({ request, params }: { request: Request; params: { id: string } }) {
|
||||
requireManagementOrigin(request);
|
||||
if (!getHost(params.id)) error(404, 'Host not found.');
|
||||
const search = new URL(request.url).searchParams;
|
||||
const scope = search.get('scope') ?? 'host';
|
||||
const phase = search.get('phase') ?? 'all';
|
||||
const page = Number(search.get('page') ?? '1');
|
||||
if (scope !== 'host' && scope !== 'fleet') error(400, 'Invalid sample scope.');
|
||||
if (phase !== 'all' && phase !== 'startup' && phase !== 'running') error(400, 'Invalid sample phase.');
|
||||
if (!Number.isSafeInteger(page) || page < 1) error(400, 'Invalid sample page.');
|
||||
return json(capacitySamples(params.id, { scope, phase, page }), { headers: { 'Cache-Control': 'no-store' } });
|
||||
}
|
||||
Reference in New Issue
Block a user