diff --git a/backend/main.py b/backend/main.py
index 6fa200b..6710eb5 100644
--- a/backend/main.py
+++ b/backend/main.py
@@ -1,4 +1,6 @@
from fastapi import FastAPI, UploadFile, File, HTTPException
+from fastapi.responses import JSONResponse, HTMLResponse
+import json as json_lib
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from typing import Optional, List
@@ -216,3 +218,70 @@ async def upload_favicon(file: UploadFile = File(...)):
with open(dest, "wb") as f:
shutil.copyfileobj(file.file, f)
return {"favicon": filename}
+
+
+@app.get("/export/json")
+async def export_json():
+ async with aiosqlite.connect(DB_PATH) as db:
+ db.row_factory = aiosqlite.Row
+ async with db.execute("SELECT * FROM categories ORDER BY position") as cur:
+ categories = [dict(r) for r in await cur.fetchall()]
+ for cat in categories:
+ async with db.execute(
+ "SELECT * FROM subcategories WHERE category_id=? ORDER BY position",
+ (cat["id"],)
+ ) as cur:
+ subs = [dict(r) for r in await cur.fetchall()]
+ for sub in subs:
+ async with db.execute(
+ "SELECT * FROM links WHERE subcategory_id=? ORDER BY position",
+ (sub["id"],)
+ ) as cur:
+ sub["links"] = [dict(r) for r in await cur.fetchall()]
+ cat["subcategories"] = subs
+ headers = {"Content-Disposition": "attachment; filename=startpage-bookmarks.json"}
+ return JSONResponse(content=categories, headers=headers)
+
+@app.get("/export/html")
+async def export_html():
+ async with aiosqlite.connect(DB_PATH) as db:
+ db.row_factory = aiosqlite.Row
+ async with db.execute("SELECT * FROM categories ORDER BY position") as cur:
+ categories = [dict(r) for r in await cur.fetchall()]
+ for cat in categories:
+ async with db.execute(
+ "SELECT * FROM subcategories WHERE category_id=? ORDER BY position",
+ (cat["id"],)
+ ) as cur:
+ subs = [dict(r) for r in await cur.fetchall()]
+ for sub in subs:
+ async with db.execute(
+ "SELECT * FROM links WHERE subcategory_id=? ORDER BY position",
+ (sub["id"],)
+ ) as cur:
+ sub["links"] = [dict(r) for r in await cur.fetchall()]
+ cat["subcategories"] = subs
+
+ lines = [
+ "",
+ "",
+ "",
+ "
Bookmarks",
+ "
Bookmarks
",
+ "
",
+ ]
+ for cat in categories:
+ lines.append("
" + cat["name"] + "
")
+ lines.append("
")
+ for sub in cat["subcategories"]:
+ lines.append("