aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc
diff options
context:
space:
mode:
authorAhmad Mujahid <55625580+AhmadMuj@users.noreply.github.com>2025-02-17 13:25:16 +0400
committerGitHub <noreply@github.com>2025-02-17 09:25:16 +0000
commite5cb9aa848009ea22c1385e4d33b7edf372979fb (patch)
tree89470d8da8aab10f30bbfccea8d1b0cea08a1408 /packages/trpc
parenta14be108736133535e2828b6bbdc8d0a69accd63 (diff)
downloadkarakeep-e5cb9aa848009ea22c1385e4d33b7edf372979fb.tar.zst
feat: Add PDF screenshot generation and display (#995)
* Updated pdf2json to 3.1.5 * Extract and store a screenshot from PDF files using pdf2pic * Installing graphicsmagick and ghostscript * Generate Missing PDF screenshot with tidyAssets worker for backward support * Display PDF screenshot instead of the PDF in web if it exists. * Display PDF screenshot in mobile app if exists. * Updated pnpm-lock.yaml * Removed console.log * Revert the unnecessary changes in package.json * Revert pnpm-lock changes * Prevent rendering PDF files if the screenshot is not generated * refactor: replace useEffect with useMemo for section initialization * feat: show PDF file download button and handle large PDFs by defaulting to screenshot view * feat: add file size to openapi spec * feature: Add Assets preprocessing in fix mode to admin actions * i18n: add reprocess_assets_fix_mode translation * i18n: Add missing ar translations * A bunch of fixes * Fix openspec schema --------- Co-authored-by: Mohamed Bassem <me@mbassem.com>
Diffstat (limited to 'packages/trpc')
-rw-r--r--packages/trpc/lib/attachments.ts5
-rw-r--r--packages/trpc/routers/admin.ts10
-rw-r--r--packages/trpc/routers/bookmarks.ts10
3 files changed, 25 insertions, 0 deletions
diff --git a/packages/trpc/lib/attachments.ts b/packages/trpc/lib/attachments.ts
index f4fda9cd..3ad79a5a 100644
--- a/packages/trpc/lib/attachments.ts
+++ b/packages/trpc/lib/attachments.ts
@@ -6,6 +6,7 @@ import { ZAssetType, zAssetTypesSchema } from "@hoarder/shared/types/bookmarks";
export function mapDBAssetTypeToUserType(assetType: AssetTypes): ZAssetType {
const map: Record<AssetTypes, z.infer<typeof zAssetTypesSchema>> = {
[AssetTypes.LINK_SCREENSHOT]: "screenshot",
+ [AssetTypes.ASSET_SCREENSHOT]: "assetScreenshot",
[AssetTypes.LINK_FULL_PAGE_ARCHIVE]: "fullPageArchive",
[AssetTypes.LINK_PRECRAWLED_ARCHIVE]: "precrawledArchive",
[AssetTypes.LINK_BANNER_IMAGE]: "bannerImage",
@@ -21,6 +22,7 @@ export function mapSchemaAssetTypeToDB(
): AssetTypes {
const map: Record<ZAssetType, AssetTypes> = {
screenshot: AssetTypes.LINK_SCREENSHOT,
+ assetScreenshot: AssetTypes.ASSET_SCREENSHOT,
fullPageArchive: AssetTypes.LINK_FULL_PAGE_ARCHIVE,
precrawledArchive: AssetTypes.LINK_PRECRAWLED_ARCHIVE,
bannerImage: AssetTypes.LINK_BANNER_IMAGE,
@@ -34,6 +36,7 @@ export function mapSchemaAssetTypeToDB(
export function humanFriendlyNameForAssertType(type: ZAssetType) {
const map: Record<ZAssetType, string> = {
screenshot: "Screenshot",
+ assetScreenshot: "Asset Screenshot",
fullPageArchive: "Full Page Archive",
precrawledArchive: "Precrawled Archive",
bannerImage: "Banner Image",
@@ -47,6 +50,7 @@ export function humanFriendlyNameForAssertType(type: ZAssetType) {
export function isAllowedToAttachAsset(type: ZAssetType) {
const map: Record<ZAssetType, boolean> = {
screenshot: true,
+ assetScreenshot: true,
fullPageArchive: false,
precrawledArchive: false,
bannerImage: true,
@@ -60,6 +64,7 @@ export function isAllowedToAttachAsset(type: ZAssetType) {
export function isAllowedToDetachAsset(type: ZAssetType) {
const map: Record<ZAssetType, boolean> = {
screenshot: true,
+ assetScreenshot: true,
fullPageArchive: true,
precrawledArchive: false,
bannerImage: true,
diff --git a/packages/trpc/routers/admin.ts b/packages/trpc/routers/admin.ts
index c7dd7575..6393c950 100644
--- a/packages/trpc/routers/admin.ts
+++ b/packages/trpc/routers/admin.ts
@@ -9,6 +9,7 @@ import {
OpenAIQueue,
SearchIndexingQueue,
TidyAssetsQueue,
+ triggerReprocessingFixMode,
triggerSearchReindex,
} from "@hoarder/shared/queues";
import {
@@ -154,6 +155,15 @@ export const adminAppRouter = router({
await Promise.all(bookmarkIds.map((b) => triggerSearchReindex(b.id)));
}),
+ reprocessAssetsFixMode: adminProcedure.mutation(async ({ ctx }) => {
+ const bookmarkIds = await ctx.db.query.bookmarkAssets.findMany({
+ columns: {
+ id: true,
+ },
+ });
+
+ await Promise.all(bookmarkIds.map((b) => triggerReprocessingFixMode(b.id)));
+ }),
reRunInferenceOnAllBookmarks: adminProcedure
.input(
z.object({
diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.ts
index 12ec9ccb..6ab863fb 100644
--- a/packages/trpc/routers/bookmarks.ts
+++ b/packages/trpc/routers/bookmarks.ts
@@ -259,6 +259,7 @@ function toZodSchema(bookmark: BookmarkQueryReturnType): ZBookmark {
assetId: asset.assetId,
fileName: asset.fileName,
sourceUrl: asset.sourceUrl,
+ size: assets.find((a) => a.id == asset.assetId)?.size,
};
break;
}
@@ -441,6 +442,7 @@ export const bookmarksAppRouter = router({
case BookmarkTypes.ASSET: {
await AssetPreprocessingQueue.enqueue({
bookmarkId: bookmark.id,
+ fixMode: false,
});
break;
}
@@ -830,6 +832,7 @@ export const bookmarksAppRouter = router({
assetType: bookmarkAssets.assetType,
fileName: bookmarkAssets.fileName,
sourceUrl: bookmarkAssets.sourceUrl ?? null,
+ size: null, // This will get filled in the asset loop
};
break;
}
@@ -881,6 +884,13 @@ export const bookmarksAppRouter = router({
}
acc[bookmarkId].content = content;
}
+ if (acc[bookmarkId].content.type == BookmarkTypes.ASSET) {
+ const content = acc[bookmarkId].content;
+ if (row.assets.id == content.assetId) {
+ // If this is the bookmark's main aset, caputure its size.
+ content.size = row.assets.size;
+ }
+ }
acc[bookmarkId].assets.push({
id: row.assets.id,
assetType: mapDBAssetTypeToUserType(row.assets.assetType),