aboutsummaryrefslogtreecommitdiffstats
path: root/web/app/api/v1
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-02-07 18:12:53 +0000
committerMohamedBassem <me@mbassem.com>2024-02-07 18:12:53 +0000
commit3745443c2b27afb833be7bcc2f3b4f486a42a571 (patch)
tree88f0a90fb100b56ad9e9f4686a1f72c50ba7d5a9 /web/app/api/v1
parent293869e1743c925519d938ebeeff033c773a1ec6 (diff)
downloadkarakeep-3745443c2b27afb833be7bcc2f3b4f486a42a571.tar.zst
[feature] Add support for deleting links
Diffstat (limited to 'web/app/api/v1')
-rw-r--r--web/app/api/v1/links/[linkId]/route.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/web/app/api/v1/links/[linkId]/route.ts b/web/app/api/v1/links/[linkId]/route.ts
new file mode 100644
index 00000000..39449d6d
--- /dev/null
+++ b/web/app/api/v1/links/[linkId]/route.ts
@@ -0,0 +1,32 @@
+import { authOptions } from "@/lib/auth";
+import { unbookmarkLink } from "@/lib/services/links";
+import { Prisma } from "@remember/db";
+
+import { getServerSession } from "next-auth";
+import { NextRequest } from "next/server";
+
+export async function DELETE(
+ _request: NextRequest,
+ { params }: { params: { linkId: string } },
+) {
+ // TODO: We probably should be using an API key here instead of the session;
+ const session = await getServerSession(authOptions);
+ if (!session) {
+ return new Response(null, { status: 401 });
+ }
+
+ try {
+ await unbookmarkLink(params.linkId, session.user.id);
+ } catch (e: unknown) {
+ if (
+ e instanceof Prisma.PrismaClientKnownRequestError &&
+ e.code === "P2025" // RecordNotFound
+ ) {
+ return new Response(null, { status: 404 });
+ } else {
+ throw e;
+ }
+ }
+
+ return new Response(null, { status: 201 });
+}