{"version":3,"file":"reseed.mjs","names":[],"sources":["../../../../../src/astro/routes/api/settings/reseed.ts"],"sourcesContent":["/**\n * Re-apply the bundled theme seed.\n *\n * POST /_emdash/api/settings/reseed\n *\n * The seed embedded in the deployed bundle is the theme's source of truth:\n * everything it defines is re-applied update-on-conflict (content included),\n * anything the site added on its own is left alone. Site identity (title,\n * tagline, URL) belongs to the admin, so those seed settings are skipped.\n * Used by the hosting platform's roll to re-sync provisioned instances with\n * their theme after a bundle update.\n */\n\nimport type { APIRoute } from \"astro\";\n\nimport { requirePerm } from \"#api/authorize.js\";\nimport { apiError, apiSuccess, handleError } from \"#api/error.js\";\nimport { applySeed } from \"#seed/apply.js\";\nimport { loadSeed } from \"#seed/load.js\";\n\nexport const prerender = false;\n\nconst IDENTITY_KEYS = [\"title\", \"tagline\", \"url\"] as const;\n\nexport const POST: APIRoute = async ({ locals }) => {\n\tconst { emdash, user } = locals;\n\tif (!emdash?.db) return apiError(\"NOT_CONFIGURED\", \"EmDash is not initialized\", 500);\n\n\tconst denied = requirePerm(user, \"settings:manage\");\n\tif (denied) return denied;\n\n\ttry {\n\t\tconst seed = await loadSeed();\n\t\tif (seed.settings) {\n\t\t\tconst settings = { ...seed.settings } as Record<string, unknown>;\n\t\t\tfor (const k of IDENTITY_KEYS) delete settings[k];\n\t\t\tseed.settings = settings as typeof seed.settings;\n\t\t}\n\t\tconst result = await applySeed(emdash.db, seed, {\n\t\t\tincludeContent: true,\n\t\t\tonConflict: \"update\",\n\t\t\tstorage: emdash.storage ?? undefined,\n\t\t});\n\t\treturn apiSuccess(result);\n\t} catch (error) {\n\t\treturn handleError(error, \"Failed to re-apply seed\", \"SEED_ERROR\");\n\t}\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAa,YAAY;AAEzB,MAAM,gBAAgB;CAAC;CAAS;CAAW;CAAM;AAEjD,MAAa,OAAiB,OAAO,EAAE,aAAa;CACnD,MAAM,EAAE,QAAQ,SAAS;AACzB,KAAI,CAAC,QAAQ,GAAI,QAAO,SAAS,kBAAkB,6BAA6B,IAAI;CAEpF,MAAM,SAAS,YAAY,MAAM,kBAAkB;AACnD,KAAI,OAAQ,QAAO;AAEnB,KAAI;EACH,MAAM,OAAO,MAAM,UAAU;AAC7B,MAAI,KAAK,UAAU;GAClB,MAAM,WAAW,EAAE,GAAG,KAAK,UAAU;AACrC,QAAK,MAAM,KAAK,cAAe,QAAO,SAAS;AAC/C,QAAK,WAAW;;AAOjB,SAAO,WALQ,MAAM,UAAU,OAAO,IAAI,MAAM;GAC/C,gBAAgB;GAChB,YAAY;GACZ,SAAS,OAAO,WAAW;GAC3B,CAAC,CACuB;UACjB,OAAO;AACf,SAAO,YAAY,OAAO,2BAA2B,aAAa"}