Files
slp-modular-cms/frontend/themes/resolveTheme.ts
T
SluijsensandClaude Sonnet 5.5 88f5d20a78 Voeg Api.AndreaSlopFotografie toe met setup-token, proxy-bewuste limiters en ASF-admin-thema
- Core: opt-in ForwardedHeaders:KnownProxies en rate limiters per clientadres
  (zonder configuratie ongewijzigd gedrag)
- Identity: optioneel setup-token (X-Setup-Token), beide setup-endpoints onder de
  login-limiter, beveiligingsgebeurtenis setup_token_rejected (5007)
- Nieuw client-project SlpModularCms.Api.AndreaSlopFotografie (Identity + Availability)
  met bijbehorende tests
- Frontend: thema asf (VITE_THEME), VITE_DEFAULT_LANGUAGE, tokenveld op de setup-pagina
- CI: jobs publish/deploy-asf-test achter ASF_TEST_DEPLOY_ENABLED
- Fix U1: 301-Location wordt nu percent-encoded (gevonden door de property-test)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 01:16:34 +01:00

47 lines
1.7 KiB
TypeScript

import fs from 'node:fs';
import path from 'node:path';
export interface ResolvedTheme {
/** Absolute path of the CSS file to import (the empty module when no theme is selected). */
css: string;
/** Absolute path of the theme favicon, or null when there is no theme or it ships none. */
favicon: string | null;
}
const THEMES_DIR = import.meta.dirname;
/** Theme folders available next to this file (each holds a theme.css). */
export function availableThemes(dir: string = THEMES_DIR): string[] {
return fs
.readdirSync(dir, { withFileTypes: true })
.filter((e) => e.isDirectory() && fs.existsSync(path.join(dir, e.name, 'theme.css')))
.map((e) => e.name)
.sort();
}
/**
* Resolves VITE_THEME to files. Unset or blank means "no theme": an empty CSS module, so the admin
* looks exactly as it always did. An unknown name is a build error, never a silent fallback, so a
* typo in the pipeline cannot ship an unthemed admin unnoticed.
*/
export function resolveTheme(name: string | undefined, dir: string = THEMES_DIR): ResolvedTheme {
const trimmed = (name ?? '').trim();
if (trimmed === '') {
return { css: path.join(dir, 'none.css'), favicon: null };
}
// The name becomes a path segment: only known theme folders are accepted.
const known = availableThemes(dir);
if (!known.includes(trimmed)) {
throw new Error(
`Unknown VITE_THEME "${trimmed}". Available themes: ${known.length > 0 ? known.join(', ') : '(none)'}.`,
);
}
const favicon = path.join(dir, trimmed, 'favicon.svg');
return {
css: path.join(dir, trimmed, 'theme.css'),
favicon: fs.existsSync(favicon) ? favicon : null,
};
}