{"version":3,"file":"export.mjs","names":[],"sources":["../../../../../../src/astro/routes/api/settings/seed/export.ts"],"sourcesContent":["/**\n * Export this site as a seed file.\n *\n * GET /_emdash/api/settings/seed/export[?format=tree]\n *\n * Schema, taxonomies, menus, widget areas, sections and content (all\n * collections) — the same format the setup wizard and `reseed` apply. Site\n * identity (title, tagline, url) is omitted: it belongs to whichever site\n * applies the seed. Used by the hosting platform to publish a project as a\n * theme (the seed is committed into the project's repo for copies to apply).\n */\n\nimport type { APIRoute } from \"astro\";\n\nimport { requirePerm } from \"#api/authorize.js\";\nimport { apiError, apiSuccess, handleError } from \"#api/error.js\";\nimport { exportSeed } from \"#seed/export.js\";\nimport { splitSeed, withSchemas } from \"#seed/fs.js\";\n\nexport const prerender = false;\n\nconst IDENTITY_KEYS = [\"title\", \"tagline\", \"url\"] as const;\n\nexport const GET: APIRoute = async ({ locals, url }) => {\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 exportSeed(emdash.db, \"all\");\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\tif (url.searchParams.get(\"format\") === \"tree\") {\n\t\t\treturn apiSuccess({ files: Object.fromEntries(withSchemas(splitSeed(seed))) });\n\t\t}\n\t\treturn apiSuccess(seed);\n\t} catch (error) {\n\t\treturn handleError(error, \"Failed to export seed\", \"SEED_EXPORT_ERROR\");\n\t}\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAa,YAAY;AAEzB,MAAM,gBAAgB;CAAC;CAAS;CAAW;CAAM;AAEjD,MAAa,MAAgB,OAAO,EAAE,QAAQ,UAAU;CACvD,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,WAAW,OAAO,IAAI,MAAM;AAC/C,MAAI,KAAK,UAAU;GAClB,MAAM,WAAW,EAAE,GAAG,KAAK,UAAU;AACrC,QAAK,MAAM,KAAK,cAAe,QAAO,SAAS;AAC/C,QAAK,WAAW;;AAEjB,MAAI,IAAI,aAAa,IAAI,SAAS,KAAK,OACtC,QAAO,WAAW,EAAE,OAAO,OAAO,YAAY,YAAY,UAAU,KAAK,CAAC,CAAC,EAAE,CAAC;AAE/E,SAAO,WAAW,KAAK;UACf,OAAO;AACf,SAAO,YAAY,OAAO,yBAAyB,oBAAoB"}