1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import { z } from "zod";
import { withErrors, ok, parseJson } from "@/lib/api";
import { requireUser } from "@/lib/auth";
import { importAll } from "@/lib/store";
const ImportSchema = z.object({
version: z.literal(1),
app: z.string(),
exportedAt: z.string().optional(),
userId: z.string().optional(),
data: z.object({
sources: z.array(z.unknown()).optional(),
todos: z.array(z.unknown()).optional(),
settings: z.record(z.string(), z.unknown()).optional(),
editions: z.array(z.unknown()).optional(),
}),
});
// POST /api/import โ restore from an export. Replaces sources + todos, merges settings.
export const POST = withErrors(async (req) => {
await requireUser(req);
const body = await parseJson(req, ImportSchema);
importAll(body.data);
return ok({ ok: true });
});
|