aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/app/api/v1/lists
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-05-18 16:58:08 +0100
committerGitHub <noreply@github.com>2025-05-18 16:58:08 +0100
commit3505cb7d6416d101a4fcb1be27fc22e0171bacd2 (patch)
treeef9f55504b8a5b20add8c0ebe916972ab4ab0178 /apps/web/app/api/v1/lists
parent74e74fa6425f072107de3a9bc9dd8f91c5ac9a7d (diff)
downloadkarakeep-3505cb7d6416d101a4fcb1be27fc22e0171bacd2.tar.zst
refactor: Migrate from NextJs's API routes to Hono based routes for the API (#1432)
* Setup Hono and migrate the highlights API there * Implement the tags and lists endpoint * Implement the bookmarks and users endpoints * Add the trpc error code adapter * Remove the old nextjs handlers * fix api key not found handling * Fix trpc error handling * Fix 204 handling * Fix search ordering * Implement the singlefile endpoint * Implement the asset serving endpoints * Implement webauth * Add hono as a catch all route under api * fix tests
Diffstat (limited to 'apps/web/app/api/v1/lists')
-rw-r--r--apps/web/app/api/v1/lists/[listId]/bookmarks/[bookmarkId]/route.ts35
-rw-r--r--apps/web/app/api/v1/lists/[listId]/bookmarks/route.ts19
-rw-r--r--apps/web/app/api/v1/lists/[listId]/route.ts55
-rw-r--r--apps/web/app/api/v1/lists/route.ts26
4 files changed, 0 insertions, 135 deletions
diff --git a/apps/web/app/api/v1/lists/[listId]/bookmarks/[bookmarkId]/route.ts b/apps/web/app/api/v1/lists/[listId]/bookmarks/[bookmarkId]/route.ts
deleted file mode 100644
index 6efe2055..00000000
--- a/apps/web/app/api/v1/lists/[listId]/bookmarks/[bookmarkId]/route.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-import { NextRequest } from "next/server";
-import { buildHandler } from "@/app/api/v1/utils/handler";
-
-export const dynamic = "force-dynamic";
-
-export const PUT = (
- req: NextRequest,
- { params }: { params: { listId: string; bookmarkId: string } },
-) =>
- buildHandler({
- req,
- handler: async ({ api }) => {
- // TODO: PUT is supposed to be idempotent, but we currently fail if the bookmark is already in the list.
- await api.lists.addToList({
- listId: params.listId,
- bookmarkId: params.bookmarkId,
- });
- return { status: 204 };
- },
- });
-
-export const DELETE = (
- req: NextRequest,
- { params }: { params: { listId: string; bookmarkId: string } },
-) =>
- buildHandler({
- req,
- handler: async ({ api }) => {
- await api.lists.removeFromList({
- listId: params.listId,
- bookmarkId: params.bookmarkId,
- });
- return { status: 204 };
- },
- });
diff --git a/apps/web/app/api/v1/lists/[listId]/bookmarks/route.ts b/apps/web/app/api/v1/lists/[listId]/bookmarks/route.ts
deleted file mode 100644
index daf78449..00000000
--- a/apps/web/app/api/v1/lists/[listId]/bookmarks/route.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { NextRequest } from "next/server";
-import { buildHandler } from "@/app/api/v1/utils/handler";
-import { adaptPagination, zPagination } from "@/app/api/v1/utils/pagination";
-import { zGetBookmarkQueryParamsSchema } from "@/app/api/v1/utils/types";
-
-export const dynamic = "force-dynamic";
-
-export const GET = (req: NextRequest, params: { params: { listId: string } }) =>
- buildHandler({
- req,
- searchParamsSchema: zPagination.and(zGetBookmarkQueryParamsSchema),
- handler: async ({ api, searchParams }) => {
- const bookmarks = await api.bookmarks.getBookmarks({
- listId: params.params.listId,
- ...searchParams,
- });
- return { status: 200, resp: adaptPagination(bookmarks) };
- },
- });
diff --git a/apps/web/app/api/v1/lists/[listId]/route.ts b/apps/web/app/api/v1/lists/[listId]/route.ts
deleted file mode 100644
index 2cddbfdb..00000000
--- a/apps/web/app/api/v1/lists/[listId]/route.ts
+++ /dev/null
@@ -1,55 +0,0 @@
-import { NextRequest } from "next/server";
-import { buildHandler } from "@/app/api/v1/utils/handler";
-
-import { zEditBookmarkListSchema } from "@karakeep/shared/types/lists";
-
-export const dynamic = "force-dynamic";
-
-export const GET = (
- req: NextRequest,
- { params }: { params: { listId: string } },
-) =>
- buildHandler({
- req,
- handler: async ({ api }) => {
- const list = await api.lists.get({
- listId: params.listId,
- });
- return {
- status: 200,
- resp: list,
- };
- },
- });
-
-export const PATCH = (
- req: NextRequest,
- { params }: { params: { listId: string } },
-) =>
- buildHandler({
- req,
- bodySchema: zEditBookmarkListSchema.omit({ listId: true }),
- handler: async ({ api, body }) => {
- const list = await api.lists.edit({
- ...body!,
- listId: params.listId,
- });
- return { status: 200, resp: list };
- },
- });
-
-export const DELETE = (
- req: NextRequest,
- { params }: { params: { listId: string } },
-) =>
- buildHandler({
- req,
- handler: async ({ api }) => {
- await api.lists.delete({
- listId: params.listId,
- });
- return {
- status: 204,
- };
- },
- });
diff --git a/apps/web/app/api/v1/lists/route.ts b/apps/web/app/api/v1/lists/route.ts
deleted file mode 100644
index 5def2506..00000000
--- a/apps/web/app/api/v1/lists/route.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-import { NextRequest } from "next/server";
-
-import { zNewBookmarkListSchema } from "@karakeep/shared/types/lists";
-
-import { buildHandler } from "../utils/handler";
-
-export const dynamic = "force-dynamic";
-
-export const GET = (req: NextRequest) =>
- buildHandler({
- req,
- handler: async ({ api }) => {
- const lists = await api.lists.list();
- return { status: 200, resp: lists };
- },
- });
-
-export const POST = (req: NextRequest) =>
- buildHandler({
- req,
- bodySchema: zNewBookmarkListSchema,
- handler: async ({ api, body }) => {
- const list = await api.lists.create(body!);
- return { status: 201, resp: list };
- },
- });