Extract dashboard simple route table

This commit is contained in:
ejclaw
2026-04-28 17:43:20 +09:00
parent 8082c61103
commit 7f4c518c23
3 changed files with 144 additions and 10 deletions

View File

@@ -46,7 +46,7 @@ import {
buildWebDashboardOverview,
sanitizeScheduledTask,
} from './web-dashboard-data.js';
import { serveValidatedAttachment } from './web-dashboard-attachments.js';
import { handleSimpleGetRoute } from './web-dashboard-routes.js';
import {
addClaudeAccountFromToken,
getActiveCodexSettingsIndex,
@@ -1571,15 +1571,14 @@ export function createWebDashboardHandler(
return jsonResponse({ error: 'Method not allowed' }, { status: 405 });
}
const simpleGetRoutes: Record<string, () => Response> = {
'/api/health': () => jsonResponse({ ok: true }),
'/api/status-snapshots': () =>
jsonResponse(readSnapshots(statusMaxAgeMs)),
'/api/tasks': () => jsonResponse(loadTasks().map(sanitizeScheduledTask)),
'/api/attachments': () => serveValidatedAttachment(url),
};
const simpleGetRoute = simpleGetRoutes[url.pathname];
if (simpleGetRoute) return simpleGetRoute();
const simpleGetRoute = handleSimpleGetRoute({
url,
statusMaxAgeMs,
readSnapshots,
loadTasks,
jsonResponse,
});
if (simpleGetRoute) return simpleGetRoute;
if (url.pathname === '/api/overview') {
const snapshots = readSnapshots(statusMaxAgeMs);