blob: ca81fc7b7357d35ec58feece76ed5a0fab04df3e (
plain)
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
26
27
28
29
30
|
import type { ActionFunctionArgs } from "react-router";
import { importDb, type DbExport } from "~/lib/db.server";
export async function action({ request }: ActionFunctionArgs) {
if (request.method !== "POST") {
return Response.json({ error: "Method not allowed" }, { status: 405 });
}
let data: DbExport;
try {
data = await request.json();
} catch {
return Response.json({ error: "Invalid JSON body" }, { status: 400 });
}
if (!data || data.version !== 3) {
return Response.json({ error: "Invalid or unsupported export format (expected version 3)" }, { status: 400 });
}
try {
const result = importDb(data);
return Response.json({ ok: true, imported: result });
} catch (e) {
return Response.json({ error: e instanceof Error ? e.message : "Import failed" }, { status: 500 });
}
}
export default function () {
return null;
}
|