summaryrefslogtreecommitdiff
path: root/app/routes/api-import.tsx
diff options
context:
space:
mode:
authoryyamashita <yyamashita@mosquit.one>2026-05-09 14:36:28 +0900
committeryyamashita <yyamashita@mosquit.one>2026-05-09 14:36:28 +0900
commit0e12e7238f48ffc2a5d35dae059c2f00c7250f3b (patch)
treebafbc876a6d3c0239c58ad888247c9e5a4161628 /app/routes/api-import.tsx
parente2f492ccae9afcc98ae7eb76bb94dc973aed60d8 (diff)
Add /api/export and /api/import endpoints for DB backup and sync
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'app/routes/api-import.tsx')
-rw-r--r--app/routes/api-import.tsx30
1 files changed, 30 insertions, 0 deletions
diff --git a/app/routes/api-import.tsx b/app/routes/api-import.tsx
new file mode 100644
index 0000000..e28a7db
--- /dev/null
+++ b/app/routes/api-import.tsx
@@ -0,0 +1,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 !== 1) {
+ return Response.json({ error: "Invalid or unsupported export format (expected version 1)" }, { 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;
+}