mirror of
https://github.com/khoaliber/dockhand.git
synced 2026-03-06 05:39:05 +00:00
Initial commit
This commit is contained in:
40
routes/api/auto-update/+server.ts
Normal file
40
routes/api/auto-update/+server.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
import { getAutoUpdateSettings } from '$lib/server/db';
|
||||
|
||||
/**
|
||||
* Batch endpoint to get all auto-update settings for an environment.
|
||||
* Returns a map of containerName -> settings for efficient lookup.
|
||||
*/
|
||||
export const GET: RequestHandler = async ({ url }) => {
|
||||
try {
|
||||
const envIdParam = url.searchParams.get('env');
|
||||
const envId = envIdParam ? parseInt(envIdParam) : undefined;
|
||||
|
||||
const settings = await getAutoUpdateSettings(envId);
|
||||
|
||||
// Convert to a map keyed by container name for efficient frontend lookup
|
||||
const settingsMap: Record<string, {
|
||||
enabled: boolean;
|
||||
scheduleType: string;
|
||||
cronExpression: string | null;
|
||||
vulnerabilityCriteria: string;
|
||||
}> = {};
|
||||
|
||||
for (const setting of settings) {
|
||||
if (setting.enabled) {
|
||||
settingsMap[setting.containerName] = {
|
||||
enabled: setting.enabled,
|
||||
scheduleType: setting.scheduleType,
|
||||
cronExpression: setting.cronExpression,
|
||||
vulnerabilityCriteria: setting.vulnerabilityCriteria || 'never'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return json(settingsMap);
|
||||
} catch (error) {
|
||||
console.error('Failed to get auto-update settings:', error);
|
||||
return json({ error: 'Failed to get auto-update settings' }, { status: 500 });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user