{"version":3,"file":"apply.mjs","names":[],"sources":["../../../../../src/astro/routes/api/color-schemes/apply.ts"],"sourcesContent":["/**\n * Apply a color scheme to this site.\n * POST /_emdash/api/color-schemes/apply  { id }  — fetch + persist; recolors live.\n */\nimport type { APIRoute } from \"astro\";\n\nimport { requirePerm } from \"#api/authorize.js\";\nimport { apiError, handleError, unwrapResult } from \"#api/error.js\";\nimport { applyColorScheme } from \"#api/handlers/color-schemes.js\";\n\nexport const prerender = false;\n\nexport const POST: APIRoute = async ({ locals, request }) => {\n\tconst { emdash, user } = locals;\n\tif (!emdash?.db) return apiError(\"NOT_CONFIGURED\", \"EmDash is not initialized\", 500);\n\tconst denied = requirePerm(user, \"settings:manage\");\n\tif (denied) return denied;\n\tlet id = \"\";\n\ttry {\n\t\tconst body = (await request.json()) as { id?: unknown };\n\t\tid = typeof body?.id === \"string\" ? body.id : \"\";\n\t} catch {\n\t\treturn apiError(\"BAD_REQUEST\", \"Expected a JSON body { id }\", 400);\n\t}\n\tif (!id) return apiError(\"BAD_REQUEST\", \"id is required\", 400);\n\ttry {\n\t\treturn unwrapResult(await applyColorScheme(emdash.db, emdash.config.marketplace, id));\n\t} catch (error) {\n\t\treturn handleError(error, \"Failed to apply color scheme\", \"COLOR_SCHEME_ERROR\");\n\t}\n};\n"],"mappings":";;;;;;;;AAUA,MAAa,YAAY;AAEzB,MAAa,OAAiB,OAAO,EAAE,QAAQ,cAAc;CAC5D,MAAM,EAAE,QAAQ,SAAS;AACzB,KAAI,CAAC,QAAQ,GAAI,QAAO,SAAS,kBAAkB,6BAA6B,IAAI;CACpF,MAAM,SAAS,YAAY,MAAM,kBAAkB;AACnD,KAAI,OAAQ,QAAO;CACnB,IAAI,KAAK;AACT,KAAI;EACH,MAAM,OAAQ,MAAM,QAAQ,MAAM;AAClC,OAAK,OAAO,MAAM,OAAO,WAAW,KAAK,KAAK;SACvC;AACP,SAAO,SAAS,eAAe,+BAA+B,IAAI;;AAEnE,KAAI,CAAC,GAAI,QAAO,SAAS,eAAe,kBAAkB,IAAI;AAC9D,KAAI;AACH,SAAO,aAAa,MAAM,iBAAiB,OAAO,IAAI,OAAO,OAAO,aAAa,GAAG,CAAC;UAC7E,OAAO;AACf,SAAO,YAAY,OAAO,gCAAgC,qBAAqB"}