Download src/app/api/export/route.ts from NAP1320/RotNot: direct link, hf CLI and curl.
- Browser
- Download file 1.81 kB
-
https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/app/api/export/route.ts
- Command line
-
hf download hf://spaces/NAP1320/RotNot/src/app/api/export/route.ts
-
curl -L -o route.ts https://huggingface.co/spaces/NAP1320/RotNot/resolve/main/src/app/api/export/route.ts
1.81 kB
| import { NextResponse } from "next/server"; | |
| import { prisma } from "@/lib/db"; | |
| import { withApiError, ApiError } from "@/lib/api-error"; | |
| import { buildExport } from "@/lib/export"; | |
| /** | |
| * GET /api/export | |
| * | |
| * Returns a full JSON export of the user's data. | |
| * Intended for data portability — download everything in one file. | |
| */ | |
| export const GET = withApiError(async () => { | |
| const user = await prisma.user.findFirst({ where: { id: 1 } }); | |
| if (!user) throw new ApiError(404, "No user found"); | |
| const [categorySkills, activities, dailyLogs, unlocks, spacedRepetition] = | |
| await Promise.all([ | |
| prisma.categorySkill.findMany({ | |
| where: { userId: 1 }, | |
| orderBy: { category: "asc" }, | |
| }), | |
| prisma.activity.findMany({ | |
| where: { userId: 1 }, | |
| orderBy: { createdAt: "desc" }, | |
| }), | |
| prisma.dailyLog.findMany({ | |
| where: { userId: 1 }, | |
| orderBy: { date: "asc" }, | |
| }), | |
| prisma.unlock.findMany({ | |
| where: { userId: 1 }, | |
| include: { | |
| node: { | |
| select: { | |
| category: true, | |
| name: true, | |
| nodeType: true, | |
| levelRequired: true, | |
| }, | |
| }, | |
| }, | |
| orderBy: { unlockedAt: "asc" }, | |
| }), | |
| prisma.spacedRepetitionItem.findMany({ | |
| where: { userId: 1 }, | |
| orderBy: { createdAt: "asc" }, | |
| }), | |
| ]); | |
| const exportData = buildExport({ | |
| user, | |
| categorySkills, | |
| activities, | |
| dailyLogs, | |
| unlocks, | |
| spacedRepetition, | |
| }); | |
| return new NextResponse(JSON.stringify(exportData, null, 2), { | |
| status: 200, | |
| headers: { | |
| "Content-Type": "application/json", | |
| "Content-Disposition": `attachment; filename="rotnot-export-${new Date().toISOString().slice(0, 10)}.json"`, | |
| }, | |
| }); | |
| }); | |