rcgit

/ karakeep

Commit 9fb80514

SHA 9fb80514773d63115a5b41787b339670326bb763
Author erik-nilcoast <138068205+erik-nilcoast at users dot noreply dot github dot com>
Author Date 2025-03-09 10:18 -0500
Committer GitHub <noreply at github dot com>
Commit Date 2025-03-09 15:18 +0000
Parent(s) 80a808048340 (diff)
Tree d88c6e8b5733

patch snapshot

feat: Expose bookmark summarization in the API (#1088)
Proxy to the TRPC Summarize mutation for use in the public API
File + - Graph
A apps/web/app/api/v1/bookmarks/[bookmarkId]/summarize/route.ts +19 -0
M packages/open-api/hoarder-openapi-spec.json +79 -0
M packages/open-api/lib/bookmarks.ts +23 -0
3 file(s) changed, 121 insertions(+), 0 deletions(-)

apps/web/app/api/v1/bookmarks/[bookmarkId]/summarize/route.ts

diff --git a/apps/web/app/api/v1/bookmarks/[bookmarkId]/summarize/route.ts b/apps/web/app/api/v1/bookmarks/[bookmarkId]/summarize/route.ts
new file mode 100644
index 00000000..ea41cad4
--- /dev/null
+++ b/apps/web/app/api/v1/bookmarks/[bookmarkId]/summarize/route.ts
@@ -0,0 +1,19 @@
+import { NextRequest } from "next/server";
+import { buildHandler } from "@/app/api/v1/utils/handler";
+
+export const dynamic = "force-dynamic";
+
+export const POST = (
+  req: NextRequest,
+  params: { params: { bookmarkId: string } },
+) =>
+  buildHandler({
+    req,
+    handler: async ({ api }) => {
+      const bookmark = await api.bookmarks.summarizeBookmark({
+        bookmarkId: params.params.bookmarkId,
+      });
+
+      return { status: 200, resp: bookmark };
+    },
+  });

packages/open-api/hoarder-openapi-spec.json

diff --git a/packages/open-api/hoarder-openapi-spec.json b/packages/open-api/hoarder-openapi-spec.json
index 3af444b8..c33d0621 100644
--- a/packages/open-api/hoarder-openapi-spec.json
+++ b/packages/open-api/hoarder-openapi-spec.json
@@ -913,6 +913,85 @@
         }
       }
     },
+    "/bookmarks/{bookmarkId}/summarize": {
+      "post": {
+        "description": "Attaches a summary to the bookmark and returns the updated record.",
+        "summary": "Summarize a bookmark",
+        "tags": [
+          "Bookmarks"
+        ],
+        "security": [
+          {
+            "bearerAuth": []
+          }
+        ],
+        "parameters": [
+          {
+            "$ref": "#/components/parameters/BookmarkId"
+          }
+        ],
+        "responses": {
+          "200": {
+            "description": "The updated bookmark with summary",
+            "content": {
+              "application/json": {
+                "schema": {
+                  "type": "object",
+                  "properties": {
+                    "id": {
+                      "type": "string"
+                    },
+                    "createdAt": {
+                      "type": "string"
+                    },
+                    "modifiedAt": {
+                      "type": "string",
+                      "nullable": true
+                    },
+                    "title": {
+                      "type": "string",
+                      "nullable": true,
+                      "maxLength": 250
+                    },
+                    "archived": {
+                      "type": "boolean"
+                    },
+                    "favourited": {
+                      "type": "boolean"
+                    },
+                    "taggingStatus": {
+                      "type": "string",
+                      "nullable": true,
+                      "enum": [
+                        "success",
+                        "failure",
+                        "pending"
+                      ]
+                    },
+                    "note": {
+                      "type": "string",
+                      "nullable": true
+                    },
+                    "summary": {
+                      "type": "string",
+                      "nullable": true
+                    }
+                  },
+                  "required": [
+                    "id",
+                    "createdAt",
+                    "modifiedAt",
+                    "archived",
+                    "favourited",
+                    "taggingStatus"
+                  ]
+                }
+              }
+            }
+          }
+        }
+      }
+    },
     "/bookmarks/{bookmarkId}/tags": {
       "post": {
         "description": "Attach tags to a bookmark",

packages/open-api/lib/bookmarks.ts

diff --git a/packages/open-api/lib/bookmarks.ts b/packages/open-api/lib/bookmarks.ts
index c7c05256..a1ab1353 100644
--- a/packages/open-api/lib/bookmarks.ts
+++ b/packages/open-api/lib/bookmarks.ts
@@ -197,6 +197,29 @@ registry.registerPath({
   },
 });
 
+registry.registerPath({
+  method: "post",
+  path: "/bookmarks/{bookmarkId}/summarize",
+  description:
+    "Attaches a summary to the bookmark and returns the updated record.",
+  summary: "Summarize a bookmark",
+  tags: ["Bookmarks"],
+  security: [{ [BearerAuth.name]: [] }],
+  request: {
+    params: z.object({ bookmarkId: BookmarkIdSchema }),
+  },
+  responses: {
+    200: {
+      description: "The updated bookmark with summary",
+      content: {
+        "application/json": {
+          schema: zBareBookmarkSchema,
+        },
+      },
+    },
+  },
+});
+
 registry.registerPath({
   method: "post",
   path: "/bookmarks/{bookmarkId}/tags",