From a4d5be3a3a031c039568b5cb4e7e2305f8e4f283 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sun, 13 Apr 2025 14:04:39 +0000 Subject: feat: Allow editing the extracted content of an asset bookmark --- packages/trpc/routers/bookmarks.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'packages/trpc/routers') 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 = { -- cgit v1.2.3-70-g09d2