A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
feat: Allow editing the extracted content of an asset bookmark
Mohamed Bassema4d5be3a3a03
diff --git a/apps/web/components/dashboard/bookmarks/EditBookmarkDialog.tsx b/apps/web/components/dashboard/bookmarks/EditBookmarkDialog.tsxindex c7745acd..ab5d0364 100644--- a/apps/web/components/dashboard/bookmarks/EditBookmarkDialog.tsx+++ b/apps/web/components/dashboard/bookmarks/EditBookmarkDialog.tsx@@ -35,6 +35,7 @@ import { CalendarIcon } from "lucide-react";import { useForm } from "react-hook-form";import { useUpdateBookmark } from "@karakeep/shared-react/hooks/bookmarks";+import { getBookmarkTitle } from "@karakeep/shared-react/utils/bookmarkUtils";import {BookmarkTypes,ZBookmark,@@ -61,11 +62,7 @@ export function EditBookmarkDialog({const bookmarkToDefault = (bookmark: ZBookmark) => ({bookmarkId: bookmark.id,summary: bookmark.summary,- title: bookmark.title- ? bookmark.title- : bookmark.content.type === BookmarkTypes.LINK- ? bookmark.content.title- : undefined,+ title: getBookmarkTitle(bookmark),createdAt: bookmark.createdAt ?? new Date(),// Link specific defaults (only if bookmark is a link)url:@@ -88,6 +85,11 @@ export function EditBookmarkDialog({bookmark.content.type === BookmarkTypes.LINK? bookmark.content.datePublished: undefined,+ // Asset specific fields+ assetContent:+ bookmark.content.type === BookmarkTypes.ASSET+ ? bookmark.content.content+ : undefined,});const form = useForm<ZUpdateBookmarksRequest>({@@ -130,6 +132,7 @@ export function EditBookmarkDialog({}, [bookmark, form, open]);const isLink = bookmark.content.type === BookmarkTypes.LINK;+ const isAsset = bookmark.content.type === BookmarkTypes.ASSET;return (<Dialog open={open} onOpenChange={setOpen}>@@ -215,6 +218,28 @@ export function EditBookmarkDialog({/>)}+ {isAsset && (+ <FormField+ control={form.control}+ name="assetContent"+ render={({ field }) => (+ <FormItem>+ <FormLabel>+ {t("bookmark_editor.extracted_content")}+ </FormLabel>+ <FormControl>+ <Textarea+ placeholder="Extracted Content"+ {...field}+ value={field.value ?? ""}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ )}+{isLink && (<div className="grid grid-cols-1 gap-4 md:grid-cols-2"><FormFielddiff --git a/apps/web/lib/i18n/locales/en/translation.json b/apps/web/lib/i18n/locales/en/translation.jsonindex 5166d6bd..f76d0f33 100644--- a/apps/web/lib/i18n/locales/en/translation.json+++ b/apps/web/lib/i18n/locales/en/translation.json@@ -374,6 +374,7 @@"publisher": "Publisher","date_published": "Date Published","pick_a_date": "Pick a date",- "save_changes": "Save changes"+ "save_changes": "Save changes",+ "extracted_content": "Extracted Content"}}diff --git a/packages/open-api/hoarder-openapi-spec.json b/packages/open-api/hoarder-openapi-spec.jsonindex 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.tsindex 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.tsindex 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 zUpdateBookmarksRequestSchemadiff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.tsindex 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 fieldsconst 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 = {