{"version":3,"file":"export.mjs","names":[],"sources":["../../../../../../src/astro/routes/api/settings/backups/export.ts"],"sourcesContent":["/**\n * One-click backup download\n *\n * GET /_emdash/api/settings/backups/export — generate a fresh backup and\n * stream it as a JSON download. Read-only (nothing is stored), so GET is\n * appropriate despite the cost of generating the payload.\n */\n\nimport type { APIRoute } from \"astro\";\n\nimport { requirePerm } from \"#api/authorize.js\";\nimport { apiError, handleError } from \"#api/error.js\";\nimport { ErrorCode } from \"#api/errors.js\";\nimport { archiveNameForDate, generateBackupJson } from \"#api/handlers/backup.js\";\n\nexport const prerender = false;\n\nexport const GET: APIRoute = async ({ locals }) => {\n\tconst { emdash, user } = locals;\n\n\tif (!emdash?.db) {\n\t\treturn apiError(\"NOT_CONFIGURED\", \"EmDash is not initialized\", 500);\n\t}\n\n\tconst denied = requirePerm(user, \"backups:manage\");\n\tif (denied) return denied;\n\n\ttry {\n\t\tconst json = await generateBackupJson(emdash.db);\n\t\treturn new Response(json, {\n\t\t\tstatus: 200,\n\t\t\theaders: {\n\t\t\t\t\"Content-Type\": \"application/json\",\n\t\t\t\t\"Content-Disposition\": `attachment; filename=\"${archiveNameForDate(new Date())}\"`,\n\t\t\t\t// Session-specific full-content export — never cacheable anywhere.\n\t\t\t\t\"Cache-Control\": \"private, no-store\",\n\t\t\t\t\"X-Content-Type-Options\": \"nosniff\",\n\t\t\t},\n\t\t});\n\t} catch (error) {\n\t\treturn handleError(error, \"Failed to generate backup\", ErrorCode.BACKUP_EXPORT_ERROR);\n\t}\n};\n"],"mappings":";;;;;;;;;;AAeA,MAAa,YAAY;AAEzB,MAAa,MAAgB,OAAO,EAAE,aAAa;CAClD,MAAM,EAAE,QAAQ,SAAS;AAEzB,KAAI,CAAC,QAAQ,GACZ,QAAO,SAAS,kBAAkB,6BAA6B,IAAI;CAGpE,MAAM,SAAS,YAAY,MAAM,iBAAiB;AAClD,KAAI,OAAQ,QAAO;AAEnB,KAAI;EACH,MAAM,OAAO,MAAM,mBAAmB,OAAO,GAAG;AAChD,SAAO,IAAI,SAAS,MAAM;GACzB,QAAQ;GACR,SAAS;IACR,gBAAgB;IAChB,uBAAuB,yBAAyB,mCAAmB,IAAI,MAAM,CAAC,CAAC;IAE/E,iBAAiB;IACjB,0BAA0B;IAC1B;GACD,CAAC;UACM,OAAO;AACf,SAAO,YAAY,OAAO,6BAA6B,UAAU,oBAAoB"}