diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-04-13 14:04:39 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2025-04-13 14:04:39 +0000 |
| commit | a4d5be3a3a031c039568b5cb4e7e2305f8e4f283 (patch) | |
| tree | c2721be51d72ea12cbe01efeee6d429de963f932 /packages | |
| parent | 8c6cfc8f5fdab4bbdae41060518c08731720976a (diff) | |
| download | karakeep-a4d5be3a3a031c039568b5cb4e7e2305f8e4f283.tar.zst | |
feat: Allow editing the extracted content of an asset bookmark
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/open-api/hoarder-openapi-spec.json | 8 | ||||
| -rw-r--r-- | packages/sdk/src/hoarder-api.d.ts | 2 | ||||
| -rw-r--r-- | packages/shared/types/bookmarks.ts | 4 | ||||
| -rw-r--r-- | packages/trpc/routers/bookmarks.ts | 20 |
4 files changed, 34 insertions, 0 deletions
diff --git a/packages/open-api/hoarder-openapi-spec.json b/packages/open-api/hoarder-openapi-spec.json index c7f91949..dfe7c761 100644 --- a/packages/open-api/hoarder-openapi-spec.json +++ b/packages/open-api/hoarder-openapi-spec.json @@ -243,6 +243,10 @@ "size": { "type": "number", "nullable": true + }, + "content": { + "type": "string", + "nullable": true } }, "required": [ @@ -958,6 +962,10 @@ "text": { "type": "string", "nullable": true + }, + "assetContent": { + "type": "string", + "nullable": true } } } diff --git a/packages/sdk/src/hoarder-api.d.ts b/packages/sdk/src/hoarder-api.d.ts index 44b8bef7..2b9986d3 100644 --- a/packages/sdk/src/hoarder-api.d.ts +++ b/packages/sdk/src/hoarder-api.d.ts @@ -277,6 +277,7 @@ export interface paths { datePublished?: string | null; dateModified?: string | null; text?: string | null; + assetContent?: string | null; }; }; }; @@ -1748,6 +1749,7 @@ export interface components { fileName?: string | null; sourceUrl?: string | null; size?: number | null; + content?: string | null; } | { /** @enum {string} */ diff --git a/packages/shared/types/bookmarks.ts b/packages/shared/types/bookmarks.ts index 883dda30..25c40bbc 100644 --- a/packages/shared/types/bookmarks.ts +++ b/packages/shared/types/bookmarks.ts @@ -67,6 +67,7 @@ export const zBookmarkedAssetSchema = z.object({ fileName: z.string().nullish(), sourceUrl: z.string().nullish(), size: z.number().nullish(), + content: z.string().nullish(), }); export type ZBookmarkedAsset = z.infer<typeof zBookmarkedAssetSchema>; @@ -206,6 +207,9 @@ export const zUpdateBookmarksRequestSchema = z.object({ // Text specific fields (optional) text: z.string().nullish(), + + // Asset specific fields (optional) + assetContent: z.string().nullish(), }); export type ZUpdateBookmarksRequest = z.infer< typeof zUpdateBookmarksRequestSchema diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts index fdb99257..7ad98b37 100644 --- a/packages/trpc/routers/bookmarks.ts +++ b/packages/trpc/routers/bookmarks.ts @@ -225,6 +225,7 @@ function toZodSchema(bookmark: BookmarkQueryReturnType): ZBookmark { fileName: asset.fileName, sourceUrl: asset.sourceUrl, size: assets.find((a) => a.id == asset.assetId)?.size, + content: asset.content, }; } @@ -485,6 +486,24 @@ export const bookmarksAppRouter = router({ somethingChanged = true; } + if (input.assetContent !== undefined) { + const result = await tx + .update(bookmarkAssets) + .set({ + content: input.assetContent, + }) + .where(and(eq(bookmarkAssets.id, input.bookmarkId))); + + if (result.changes == 0) { + throw new TRPCError({ + code: "BAD_REQUEST", + message: + "Attempting to set asset content for non-asset type bookmark", + }); + } + somethingChanged = true; + } + // Update common bookmark fields const commonUpdateData: Partial<{ title: string | null; @@ -861,6 +880,7 @@ export const bookmarksAppRouter = router({ fileName: row.bookmarkAssets.fileName, sourceUrl: row.bookmarkAssets.sourceUrl ?? null, size: null, // This will get filled in the asset loop + content: row.bookmarkAssets.content ?? null, }; } else { content = { |
