aboutsummaryrefslogtreecommitdiffstats
path: root/packages/api
diff options
context:
space:
mode:
Diffstat (limited to 'packages/api')
-rw-r--r--packages/api/index.ts4
-rw-r--r--packages/api/routes/backups.ts44
2 files changed, 47 insertions, 1 deletions
diff --git a/packages/api/index.ts b/packages/api/index.ts
index 7bf9084d..3df7b429 100644
--- a/packages/api/index.ts
+++ b/packages/api/index.ts
@@ -10,6 +10,7 @@ import { Context } from "@karakeep/trpc";
import trpcAdapter from "./middlewares/trpcAdapter";
import admin from "./routes/admin";
import assets from "./routes/assets";
+import backups from "./routes/backups";
import bookmarks from "./routes/bookmarks";
import health from "./routes/health";
import highlights from "./routes/highlights";
@@ -37,7 +38,8 @@ const v1 = new Hono<{
.route("/users", users)
.route("/assets", assets)
.route("/admin", admin)
- .route("/rss", rss);
+ .route("/rss", rss)
+ .route("/backups", backups);
const app = new Hono<{
Variables: {
diff --git a/packages/api/routes/backups.ts b/packages/api/routes/backups.ts
new file mode 100644
index 00000000..949c826f
--- /dev/null
+++ b/packages/api/routes/backups.ts
@@ -0,0 +1,44 @@
+import { Hono } from "hono";
+
+import { authMiddleware } from "../middlewares/auth";
+
+const app = new Hono()
+ .use(authMiddleware)
+
+ // GET /backups
+ .get("/", async (c) => {
+ const backups = await c.var.api.backups.list();
+ return c.json(backups, 200);
+ })
+
+ // POST /backups
+ .post("/", async (c) => {
+ const backup = await c.var.api.backups.triggerBackup();
+ return c.json(backup, 201);
+ })
+
+ // GET /backups/[backupId]
+ .get("/:backupId", async (c) => {
+ const backupId = c.req.param("backupId");
+ const backup = await c.var.api.backups.get({ backupId });
+ return c.json(backup, 200);
+ })
+
+ // GET /backups/[backupId]/download
+ .get("/:backupId/download", async (c) => {
+ const backupId = c.req.param("backupId");
+ const backup = await c.var.api.backups.get({ backupId });
+ if (!backup.assetId) {
+ return c.json({ error: "Backup not found" }, 404);
+ }
+ return c.redirect(`/api/assets/${backup.assetId}`);
+ })
+
+ // DELETE /backups/[backupId]
+ .delete("/:backupId", async (c) => {
+ const backupId = c.req.param("backupId");
+ await c.var.api.backups.delete({ backupId });
+ return c.body(null, 204);
+ });
+
+export default app;