mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-07 17:34:23 +00:00
50e64b058b
First slice of Phase 4 (route extraction). Pulls 8 well-tested, mostly
independent route groups out of index.ts into focused Router files. No
behavior change; every handler body moves verbatim.
New route files under backend/src/routes/:
- meta.ts /api/health, /api/meta (mounted before authGate)
- license.ts /api/license/* + /api/system/update,
exports scheduleLocalUpdate for the fleet route
- permissions.ts /api/permissions/me
- convert.ts POST /api/convert
- alerts.ts /api/alerts/*
- labels.ts /api/labels/* + PUT /api/stacks/:name/labels
(exported as stackLabelsRouter)
- apiTokens.ts /api/api-tokens/*
- auditLog.ts /api/audit-log/*
Shared helper lifts:
- helpers/cacheInvalidation.ts: invalidateNodeCaches()
- middleware/tierGates.ts: requireBody (was inline in index.ts)
- utils/errors.ts: isSqliteUniqueViolation (was inline in index.ts)
- middleware/apiTokenScope.ts: rejectApiTokenScope() helper (new)
- utils/csv.ts: escapeCsvField() (new)
index.ts drops from ~7520 to ~6775 lines and now mounts the routers right
after enforceApiTokenScope. The remote proxy and fleet/auth/webhooks/users
routes remain inline in index.ts pending later Phase 4 slices.
Code review fixes: rejectApiTokenScope helper replaces duplicated
`if (req.apiTokenScope) 403 SCOPE_DENIED` blocks in apiTokens.ts and
license.ts; escapeCsvField replaces the inline CSV escape in auditLog.ts.
17 lines
603 B
TypeScript
17 lines
603 B
TypeScript
import { CacheService } from '../services/CacheService';
|
|
|
|
/**
|
|
* Drop the per-node caches affected by a stack or container mutation so the
|
|
* next dashboard poll shows fresh state instead of stale reads.
|
|
*
|
|
* Also drops the global `project-name-map` since stack writes (create,
|
|
* delete, rename, compose edits) can reshape the on-disk layout used to
|
|
* build it.
|
|
*/
|
|
export function invalidateNodeCaches(nodeId: number): void {
|
|
const cache = CacheService.getInstance();
|
|
cache.invalidate(`stats:${nodeId}`);
|
|
cache.invalidate(`stack-statuses:${nodeId}`);
|
|
cache.invalidate('project-name-map');
|
|
}
|