/** * The site's applied color scheme. * GET /_emdash/api/color-schemes/current — read it (or null). * DELETE /_emdash/api/color-schemes/current — clear it (revert to theme defaults). */ import type { APIRoute } from "astro"; import { requirePerm } from "#api/authorize.js"; import { apiError, handleError, unwrapResult } from "#api/error.js"; import { clearColorScheme, getAppliedColorScheme } from "#api/handlers/color-schemes.js"; export const prerender = false; export const GET: APIRoute = async ({ locals }) => { const { emdash, user } = locals; if (!emdash?.db) return apiError("NOT_CONFIGURED", "EmDash is not initialized", 500); const denied = requirePerm(user, "settings:read"); if (denied) return denied; const scheme = await getAppliedColorScheme(emdash.db); return Response.json({ success: true, data: { scheme } }); }; export const DELETE: APIRoute = async ({ locals }) => { const { emdash, user } = locals; if (!emdash?.db) return apiError("NOT_CONFIGURED", "EmDash is not initialized", 500); const denied = requirePerm(user, "settings:manage"); if (denied) return denied; try { return unwrapResult(await clearColorScheme(emdash.db)); } catch (error) { return handleError(error, "Failed to clear color scheme", "COLOR_SCHEME_ERROR"); } };