aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/routers
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-07-06 21:50:23 +0000
committerMohamed Bassem <me@mbassem.com>2025-07-06 22:04:56 +0000
commitdee3a4d44ddb1999e7dec383889246e87f202d92 (patch)
tree1984234f17eed886bc834543e1505ddbfb43228f /packages/trpc/routers
parent362be3008aa8b036c4c448a86e459044af8784c2 (diff)
downloadkarakeep-dee3a4d44ddb1999e7dec383889246e87f202d92.tar.zst
feat: Store large html content in the asset db
Diffstat (limited to 'packages/trpc/routers')
-rw-r--r--packages/trpc/routers/bookmarks.ts21
1 files changed, 15 insertions, 6 deletions
diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts
index f1fe10d7..77f40878 100644
--- a/packages/trpc/routers/bookmarks.ts
+++ b/packages/trpc/routers/bookmarks.ts
@@ -118,7 +118,7 @@ async function getBookmark(
});
}
- return toZodSchema(bookmark, includeContent);
+ return await toZodSchema(bookmark, includeContent);
}
async function attemptToDedupLink(ctx: AuthedContext, url: string) {
@@ -177,10 +177,10 @@ async function cleanupAssetForBookmark(
);
}
-function toZodSchema(
+async function toZodSchema(
bookmark: BookmarkQueryReturnType,
includeContent: boolean,
-): ZBookmark {
+): Promise<ZBookmark> {
const { tagsOnBookmarks, link, text, asset, assets, ...rest } = bookmark;
let content: ZBookmarkContent = {
@@ -208,7 +208,9 @@ function toZodSchema(
description: link.description,
imageUrl: link.imageUrl,
favicon: link.favicon,
- htmlContent: includeContent ? link.htmlContent : null,
+ htmlContent: includeContent
+ ? await Bookmark.getBookmarkHtmlContent(link, bookmark.userId)
+ : null,
crawledAt: link.crawledAt,
author: link.author,
publisher: link.publisher,
@@ -806,7 +808,9 @@ export const bookmarksAppRouter = router({
}
return {
- bookmarks: results.map((b) => toZodSchema(b, input.includeContent)),
+ bookmarks: await Promise.all(
+ results.map((b) => toZodSchema(b, input.includeContent)),
+ ),
nextCursor:
resp.hits.length + resp.offset >= resp.estimatedTotalHits
? null
@@ -1052,10 +1056,15 @@ export const bookmarksAppRouter = router({
});
}
+ const content = await Bookmark.getBookmarkPlainTextContent(
+ bookmark,
+ ctx.user.id,
+ );
+
const bookmarkDetails = `
Title: ${bookmark.title ?? ""}
Description: ${bookmark.description ?? ""}
-Content: ${bookmark.content ?? ""}
+Content: ${content}
Publisher: ${bookmark.publisher ?? ""}
Author: ${bookmark.author ?? ""}
`;