import { Router } from 'express'; import { z } from 'zod'; import { asyncWrap } from '../errors.js'; import { requireOwner } from '../cap.js'; import { validate } from '../validate.js'; import * as settings from '../../db/repos/app_settings.js'; export const router = Router(); // Theme = a small map of palette-var overrides, e.g. { accent: '#ff4f2e' }. // Keys are short slugs (mapped to -- on the client); values must be hex, // so a saved theme can never inject arbitrary CSS. const themeSchema = z.record( z.string().regex(/^[a-z0-9-]{1,24}$/), z.string().regex(/^#[0-9a-fA-F]{3,8}$/) ); router.get('/', asyncWrap(async (_req, res) => res.json(await settings.get('theme', {})))); router.put('/', requireOwner, validate({ body: themeSchema }), asyncWrap(async (req, res) => { res.json(await settings.set('theme', req.body)); }));