1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import { requireUser } from "@/lib/auth";
import { exportAll } from "@/lib/store";
// GET /api/export โ full JSON export of the dashboard's local data.
export async function GET(req: Request) {
const userId = await requireUser(req);
const payload = {
version: 1,
app: process.env.APP_SLUG ?? "personal-dashboard",
exportedAt: new Date().toISOString(),
userId,
data: exportAll(),
};
const filename = `${payload.app}-${payload.exportedAt.slice(0, 10)}.json`;
return new Response(JSON.stringify(payload, null, 2), {
headers: {
"Content-Type": "application/json",
"Content-Disposition": `attachment; filename="${filename}"`,
},
});
}
|