aboutsummaryrefslogtreecommitdiffstats
path: root/packages/open-api/lib/bookmarks.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-01-04 14:03:42 +0000
committerMohamed Bassem <me@mbassem.com>2025-01-04 14:03:42 +0000
commit4439c91f426a8c8a13c4a84c8cb685ae67cc07e6 (patch)
tree5704485d5ac6db9ae6900a0e0371a74736bff93c /packages/open-api/lib/bookmarks.ts
parenteb0d82159060ff8c278172d01725076a9eef30c0 (diff)
downloadkarakeep-4439c91f426a8c8a13c4a84c8cb685ae67cc07e6.tar.zst
feat: Expose asset manipulation endpoints in the REST API
Diffstat (limited to 'packages/open-api/lib/bookmarks.ts')
-rw-r--r--packages/open-api/lib/bookmarks.ts92
1 files changed, 92 insertions, 0 deletions
diff --git a/packages/open-api/lib/bookmarks.ts b/packages/open-api/lib/bookmarks.ts
index 12a122fa..09288a4b 100644
--- a/packages/open-api/lib/bookmarks.ts
+++ b/packages/open-api/lib/bookmarks.ts
@@ -5,6 +5,7 @@ import {
import { z } from "zod";
import {
+ zAssetSchema,
zBareBookmarkSchema,
zManipulatedTagSchema,
zNewBookmarkRequestSchema,
@@ -23,6 +24,17 @@ import { TagIdSchema } from "./tags";
export const registry = new OpenAPIRegistry();
extendZodWithOpenApi(z);
+export const AssetIdSchema = registry.registerParameter(
+ "AssetId",
+ z.string().openapi({
+ param: {
+ name: "assetId",
+ in: "path",
+ },
+ example: "ieidlxygmwj87oxz5hxttoc8",
+ }),
+);
+
export const BookmarkIdSchema = registry.registerParameter(
"BookmarkId",
z.string().openapi({
@@ -240,3 +252,83 @@ registry.registerPath({
},
},
});
+
+registry.registerPath({
+ method: "post",
+ path: "/bookmarks/{bookmarkId}/assets",
+ description: "Attach a new asset to a bookmark",
+ summary: "Attach asset",
+ tags: ["Bookmarks"],
+ security: [{ [BearerAuth.name]: [] }],
+ request: {
+ params: z.object({ bookmarkId: BookmarkIdSchema }),
+ body: {
+ description: "The asset to attach",
+ content: {
+ "application/json": {
+ schema: zAssetSchema,
+ },
+ },
+ },
+ },
+ responses: {
+ 201: {
+ description: "The attached asset",
+ content: {
+ "application/json": {
+ schema: zAssetSchema,
+ },
+ },
+ },
+ },
+});
+
+registry.registerPath({
+ method: "put",
+ path: "/bookmarks/{bookmarkId}/assets/{assetId}",
+ description: "Replace an existing asset with a new one",
+ summary: "Replace asset",
+ tags: ["Bookmarks"],
+ security: [{ [BearerAuth.name]: [] }],
+ request: {
+ params: z.object({
+ bookmarkId: BookmarkIdSchema,
+ assetId: AssetIdSchema,
+ }),
+ body: {
+ description: "The new asset to replace with",
+ content: {
+ "application/json": {
+ schema: z.object({
+ assetId: z.string(),
+ }),
+ },
+ },
+ },
+ },
+ responses: {
+ 204: {
+ description: "No content - asset was replaced successfully",
+ },
+ },
+});
+
+registry.registerPath({
+ method: "delete",
+ path: "/bookmarks/{bookmarkId}/assets/{assetId}",
+ description: "Detach an asset from a bookmark",
+ summary: "Detach asset",
+ tags: ["Bookmarks"],
+ security: [{ [BearerAuth.name]: [] }],
+ request: {
+ params: z.object({
+ bookmarkId: BookmarkIdSchema,
+ assetId: AssetIdSchema,
+ }),
+ },
+ responses: {
+ 204: {
+ description: "No content - asset was detached successfully",
+ },
+ },
+});