A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
feature: Full page archival with monolith. Fixes #132
MohamedBassemdedc5fb24536
diff --git a/apps/web/app/api/assets/route.ts b/apps/web/app/api/assets/route.tsindex f1a17fc9..9028f556 100644--- a/apps/web/app/api/assets/route.ts+++ b/apps/web/app/api/assets/route.ts@@ -5,7 +5,7 @@ import type { ZUploadResponse } from "@hoarder/shared/types/uploads";import {newAssetId,saveAsset,- SUPPORTED_ASSET_TYPES,+ SUPPORTED_UPLOAD_ASSET_TYPES,} from "@hoarder/shared/assetdb";import serverConfig from "@hoarder/shared/config";@@ -29,7 +29,7 @@ export async function POST(request: Request) {let contentType;if (data instanceof File) {contentType = data.type;- if (!SUPPORTED_ASSET_TYPES.has(contentType)) {+ if (!SUPPORTED_UPLOAD_ASSET_TYPES.has(contentType)) {return Response.json({ error: "Unsupported asset type" },{ status: 400 },diff --git a/apps/web/components/dashboard/preview/LinkContentSection.tsx b/apps/web/components/dashboard/preview/LinkContentSection.tsxindex 29001c7f..3aeacdcd 100644--- a/apps/web/components/dashboard/preview/LinkContentSection.tsx+++ b/apps/web/components/dashboard/preview/LinkContentSection.tsx@@ -12,6 +12,16 @@ import { ScrollArea } from "@radix-ui/react-scroll-area";import { ZBookmark, ZBookmarkedLink } from "@hoarder/shared/types/bookmarks";+function FullPageArchiveSection({ link }: { link: ZBookmarkedLink }) {+ return (+ <iframe+ title={link.url}+ src={`/api/assets/${link.fullPageArchiveAssetId}`}+ className="relative h-full min-w-full"+ />+ );+}+function ScreenshotSection({ link }: { link: ZBookmarkedLink }) {return (<div className="relative h-full min-w-full">@@ -60,6 +70,8 @@ export default function LinkContentSection({let content;if (section === "cached") {content = <CachedContentSection link={bookmark.content} />;+ } else if (section === "archive") {+ content = <FullPageArchiveSection link={bookmark.content} />;} else {content = <ScreenshotSection link={bookmark.content} />;}@@ -79,6 +91,12 @@ export default function LinkContentSection({>Screenshot</SelectItem>+ <SelectItem+ value="archive"+ disabled={!bookmark.content.fullPageArchiveAssetId}+ >+ Archive+ </SelectItem></SelectGroup></SelectContent></Select>diff --git a/apps/workers/crawlerWorker.ts b/apps/workers/crawlerWorker.tsindex fe5bc43b..87632019 100644--- a/apps/workers/crawlerWorker.ts+++ b/apps/workers/crawlerWorker.ts@@ -7,6 +7,7 @@ import { Mutex } from "async-mutex";import { Worker } from "bullmq";import DOMPurify from "dompurify";import { eq } from "drizzle-orm";+import { execa } from "execa";import { isShuttingDown } from "exit";import { JSDOM } from "jsdom";import metascraper from "metascraper";@@ -26,7 +27,12 @@ import { withTimeout } from "utils";import type { ZCrawlLinkRequest } from "@hoarder/shared/queues";import { db } from "@hoarder/db";import { bookmarkLinks, bookmarks } from "@hoarder/db/schema";-import { deleteAsset, newAssetId, saveAsset } from "@hoarder/shared/assetdb";+import {+ deleteAsset,+ newAssetId,+ saveAsset,+ saveAssetFromFile,+} from "@hoarder/shared/assetdb";import serverConfig from "@hoarder/shared/config";import logger from "@hoarder/shared/logger";import {@@ -197,6 +203,7 @@ async function getBookmarkDetails(bookmarkId: string) {userId: bookmark.userId,screenshotAssetId: bookmark.link.screenshotAssetId,imageAssetId: bookmark.link.imageAssetId,+ fullPageArchiveAssetId: bookmark.link.fullPageArchiveAssetId,};}@@ -375,6 +382,42 @@ async function downloadAndStoreImage(}}+async function archiveWebpage(+ html: string,+ url: string,+ userId: string,+ jobId: string,+) {+ if (!serverConfig.crawler.fullPageArchive) {+ return;+ }+ logger.info(`[Crawler][${jobId}] Will attempt to archive page ...`);+ const urlParsed = new URL(url);+ const baseUrl = `${urlParsed.protocol}//${urlParsed.host}`;++ const assetId = newAssetId();+ const assetPath = `/tmp/${assetId}`;++ await execa({+ input: html,+ })`monolith - -Ije -t 5 -b ${baseUrl} -o ${assetPath}`;++ await saveAssetFromFile({+ userId,+ assetId,+ assetPath,+ metadata: {+ contentType: "text/html",+ },+ });++ logger.info(+ `[Crawler][${jobId}] Done archiving the page as assertId: ${assetId}`,+ );++ return assetId;+}+async function runCrawler(job: Job<ZCrawlLinkRequest, void>) {const jobId = job.id ?? "unknown";@@ -392,6 +435,7 @@ async function runCrawler(job: Job<ZCrawlLinkRequest, void>) {userId,screenshotAssetId: oldScreenshotAssetId,imageAssetId: oldImageAssetId,+ fullPageArchiveAssetId: oldFullPageArchiveAssetId,} = await getBookmarkDetails(bookmarkId);logger.info(@@ -453,4 +497,24 @@ async function runCrawler(job: Job<ZCrawlLinkRequest, void>) {bookmarkId,type: "index",});++ // Do the archival as a separate last step as it has the potential for failure+ const fullPageArchiveAssetId = await archiveWebpage(+ htmlContent,+ browserUrl,+ userId,+ jobId,+ );+ await db+ .update(bookmarkLinks)+ .set({+ fullPageArchiveAssetId,+ })+ .where(eq(bookmarkLinks.id, bookmarkId));++ if (oldFullPageArchiveAssetId) {+ deleteAsset({ userId, assetId: oldFullPageArchiveAssetId }).catch(+ () => ({}),+ );+ }}diff --git a/apps/workers/package.json b/apps/workers/package.jsonindex 7975cc84..b74f9ec9 100644--- a/apps/workers/package.json+++ b/apps/workers/package.json@@ -14,6 +14,7 @@"dompurify": "^3.0.9","dotenv": "^16.4.1","drizzle-orm": "^0.29.4",+ "execa": "^9.1.0","jsdom": "^24.0.0","metascraper": "^5.43.4","metascraper-amazon": "^5.45.0",diff --git a/docker/Dockerfile b/docker/Dockerfileindex 250c4c82..95d23f8d 100644--- a/docker/Dockerfile+++ b/docker/Dockerfile@@ -74,6 +74,7 @@ RUN --mount=type=cache,id=pnpm_workers,target=/pnpm/store pnpm deploy --node-linFROM node:21-alpine AS workersWORKDIR /app+RUN apk add --no-cache monolithCOPY --from=workers_builder /prod apps/workersdiff --git a/packages/db/drizzle/0022_tough_nextwave.sql b/packages/db/drizzle/0022_tough_nextwave.sqlnew file mode 100644index 00000000..234d1c2e--- /dev/null+++ b/packages/db/drizzle/0022_tough_nextwave.sql@@ -0,0 +1 @@+ALTER TABLE bookmarkLinks ADD `fullPageArchiveAssetId` text;\ No newline at end of filediff --git a/packages/db/drizzle/meta/0022_snapshot.json b/packages/db/drizzle/meta/0022_snapshot.jsonnew file mode 100644index 00000000..3d8c7441--- /dev/null+++ b/packages/db/drizzle/meta/0022_snapshot.json@@ -0,0 +1,1015 @@+{+ "version": "5",+ "dialect": "sqlite",+ "id": "f2897961-faba-4fc4-9d82-85e7cf316218",+ "prevId": "35f45396-0455-4384-b42c-e9eb62cb3128",+ "tables": {+ "account": {+ "name": "account",+ "columns": {+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "providerAccountId": {+ "name": "providerAccountId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "refresh_token": {+ "name": "refresh_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "access_token": {+ "name": "access_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "expires_at": {+ "name": "expires_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "token_type": {+ "name": "token_type",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "scope": {+ "name": "scope",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "id_token": {+ "name": "id_token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "session_state": {+ "name": "session_state",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "account_userId_user_id_fk": {+ "name": "account_userId_user_id_fk",+ "tableFrom": "account",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "account_provider_providerAccountId_pk": {+ "columns": [+ "provider",+ "providerAccountId"+ ],+ "name": "account_provider_providerAccountId_pk"+ }+ },+ "uniqueConstraints": {}+ },+ "apiKey": {+ "name": "apiKey",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "keyId": {+ "name": "keyId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "keyHash": {+ "name": "keyHash",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "apiKey_keyId_unique": {+ "name": "apiKey_keyId_unique",+ "columns": [+ "keyId"+ ],+ "isUnique": true+ },+ "apiKey_name_userId_unique": {+ "name": "apiKey_name_userId_unique",+ "columns": [+ "name",+ "userId"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "apiKey_userId_user_id_fk": {+ "name": "apiKey_userId_user_id_fk",+ "tableFrom": "apiKey",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "bookmarkAssets": {+ "name": "bookmarkAssets",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "assetType": {+ "name": "assetType",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "assetId": {+ "name": "assetId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "content": {+ "name": "content",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "metadata": {+ "name": "metadata",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "fileName": {+ "name": "fileName",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "bookmarkAssets_id_bookmarks_id_fk": {+ "name": "bookmarkAssets_id_bookmarks_id_fk",+ "tableFrom": "bookmarkAssets",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "bookmarkLinks": {+ "name": "bookmarkLinks",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "url": {+ "name": "url",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "imageUrl": {+ "name": "imageUrl",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "favicon": {+ "name": "favicon",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "content": {+ "name": "content",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "htmlContent": {+ "name": "htmlContent",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "screenshotAssetId": {+ "name": "screenshotAssetId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "fullPageArchiveAssetId": {+ "name": "fullPageArchiveAssetId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "imageAssetId": {+ "name": "imageAssetId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "crawledAt": {+ "name": "crawledAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "crawlStatus": {+ "name": "crawlStatus",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'pending'"+ }+ },+ "indexes": {+ "bookmarkLinks_url_idx": {+ "name": "bookmarkLinks_url_idx",+ "columns": [+ "url"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "bookmarkLinks_id_bookmarks_id_fk": {+ "name": "bookmarkLinks_id_bookmarks_id_fk",+ "tableFrom": "bookmarkLinks",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "bookmarkLists": {+ "name": "bookmarkLists",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "icon": {+ "name": "icon",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "parentId": {+ "name": "parentId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "bookmarkLists_userId_idx": {+ "name": "bookmarkLists_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "bookmarkLists_userId_user_id_fk": {+ "name": "bookmarkLists_userId_user_id_fk",+ "tableFrom": "bookmarkLists",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "bookmarkLists_parentId_bookmarkLists_id_fk": {+ "name": "bookmarkLists_parentId_bookmarkLists_id_fk",+ "tableFrom": "bookmarkLists",+ "tableTo": "bookmarkLists",+ "columnsFrom": [+ "parentId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "bookmarkTags": {+ "name": "bookmarkTags",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "bookmarkTags_name_idx": {+ "name": "bookmarkTags_name_idx",+ "columns": [+ "name"+ ],+ "isUnique": false+ },+ "bookmarkTags_userId_idx": {+ "name": "bookmarkTags_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "bookmarkTags_userId_name_unique": {+ "name": "bookmarkTags_userId_name_unique",+ "columns": [+ "userId",+ "name"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "bookmarkTags_userId_user_id_fk": {+ "name": "bookmarkTags_userId_user_id_fk",+ "tableFrom": "bookmarkTags",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "bookmarkTexts": {+ "name": "bookmarkTexts",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "text": {+ "name": "text",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "bookmarkTexts_id_bookmarks_id_fk": {+ "name": "bookmarkTexts_id_bookmarks_id_fk",+ "tableFrom": "bookmarkTexts",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "bookmarks": {+ "name": "bookmarks",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "archived": {+ "name": "archived",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "favourited": {+ "name": "favourited",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "taggingStatus": {+ "name": "taggingStatus",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'pending'"+ },+ "note": {+ "name": "note",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "bookmarks_userId_idx": {+ "name": "bookmarks_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "bookmarks_archived_idx": {+ "name": "bookmarks_archived_idx",+ "columns": [+ "archived"+ ],+ "isUnique": false+ },+ "bookmarks_favourited_idx": {+ "name": "bookmarks_favourited_idx",+ "columns": [+ "favourited"+ ],+ "isUnique": false+ },+ "bookmarks_createdAt_idx": {+ "name": "bookmarks_createdAt_idx",+ "columns": [+ "createdAt"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "bookmarks_userId_user_id_fk": {+ "name": "bookmarks_userId_user_id_fk",+ "tableFrom": "bookmarks",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "bookmarksInLists": {+ "name": "bookmarksInLists",+ "columns": {+ "bookmarkId": {+ "name": "bookmarkId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "listId": {+ "name": "listId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "addedAt": {+ "name": "addedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "bookmarksInLists_bookmarkId_idx": {+ "name": "bookmarksInLists_bookmarkId_idx",+ "columns": [+ "bookmarkId"+ ],+ "isUnique": false+ },+ "bookmarksInLists_listId_idx": {+ "name": "bookmarksInLists_listId_idx",+ "columns": [+ "listId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "bookmarksInLists_bookmarkId_bookmarks_id_fk": {+ "name": "bookmarksInLists_bookmarkId_bookmarks_id_fk",+ "tableFrom": "bookmarksInLists",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "bookmarkId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "bookmarksInLists_listId_bookmarkLists_id_fk": {+ "name": "bookmarksInLists_listId_bookmarkLists_id_fk",+ "tableFrom": "bookmarksInLists",+ "tableTo": "bookmarkLists",+ "columnsFrom": [+ "listId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "bookmarksInLists_bookmarkId_listId_pk": {+ "columns": [+ "bookmarkId",+ "listId"+ ],+ "name": "bookmarksInLists_bookmarkId_listId_pk"+ }+ },+ "uniqueConstraints": {}+ },+ "session": {+ "name": "session",+ "columns": {+ "sessionToken": {+ "name": "sessionToken",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "expires": {+ "name": "expires",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "session_userId_user_id_fk": {+ "name": "session_userId_user_id_fk",+ "tableFrom": "session",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "tagsOnBookmarks": {+ "name": "tagsOnBookmarks",+ "columns": {+ "bookmarkId": {+ "name": "bookmarkId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "tagId": {+ "name": "tagId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "attachedAt": {+ "name": "attachedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "attachedBy": {+ "name": "attachedBy",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "tagsOnBookmarks_tagId_idx": {+ "name": "tagsOnBookmarks_tagId_idx",+ "columns": [+ "bookmarkId"+ ],+ "isUnique": false+ },+ "tagsOnBookmarks_bookmarkId_idx": {+ "name": "tagsOnBookmarks_bookmarkId_idx",+ "columns": [+ "bookmarkId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "tagsOnBookmarks_bookmarkId_bookmarks_id_fk": {+ "name": "tagsOnBookmarks_bookmarkId_bookmarks_id_fk",+ "tableFrom": "tagsOnBookmarks",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "bookmarkId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "tagsOnBookmarks_tagId_bookmarkTags_id_fk": {+ "name": "tagsOnBookmarks_tagId_bookmarkTags_id_fk",+ "tableFrom": "tagsOnBookmarks",+ "tableTo": "bookmarkTags",+ "columnsFrom": [+ "tagId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "tagsOnBookmarks_bookmarkId_tagId_pk": {+ "columns": [+ "bookmarkId",+ "tagId"+ ],+ "name": "tagsOnBookmarks_bookmarkId_tagId_pk"+ }+ },+ "uniqueConstraints": {}+ },+ "user": {+ "name": "user",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "emailVerified": {+ "name": "emailVerified",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "image": {+ "name": "image",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "password": {+ "name": "password",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'user'"+ }+ },+ "indexes": {+ "user_email_unique": {+ "name": "user_email_unique",+ "columns": [+ "email"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "verificationToken": {+ "name": "verificationToken",+ "columns": {+ "identifier": {+ "name": "identifier",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "expires": {+ "name": "expires",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {+ "verificationToken_identifier_token_pk": {+ "columns": [+ "identifier",+ "token"+ ],+ "name": "verificationToken_identifier_token_pk"+ }+ },+ "uniqueConstraints": {}+ }+ },+ "enums": {},+ "_meta": {+ "schemas": {},+ "tables": {},+ "columns": {}+ }+}\ No newline at end of filediff --git a/packages/db/drizzle/meta/_journal.json b/packages/db/drizzle/meta/_journal.jsonindex 2cea64e5..29fa84f0 100644--- a/packages/db/drizzle/meta/_journal.json+++ b/packages/db/drizzle/meta/_journal.json@@ -155,6 +155,13 @@"when": 1716031428677,"tag": "0021_magical_firebrand","breakpoints": true+ },+ {+ "idx": 22,+ "version": "5",+ "when": 1716679762529,+ "tag": "0022_tough_nextwave",+ "breakpoints": true}]}\ No newline at end of filediff --git a/packages/db/schema.ts b/packages/db/schema.tsindex fa0777f4..3fd7897f 100644--- a/packages/db/schema.ts+++ b/packages/db/schema.ts@@ -142,6 +142,7 @@ export const bookmarkLinks = sqliteTable("bookmarkLinks", {content: text("content"),htmlContent: text("htmlContent"),screenshotAssetId: text("screenshotAssetId"),+ fullPageArchiveAssetId: text("fullPageArchiveAssetId"),imageAssetId: text("imageAssetId"),crawledAt: integer("crawledAt", { mode: "timestamp" }),crawlStatus: text("crawlStatus", {diff --git a/packages/shared/assetdb.ts b/packages/shared/assetdb.tsindex c070ad54..4cea06b0 100644--- a/packages/shared/assetdb.ts+++ b/packages/shared/assetdb.ts@@ -6,13 +6,20 @@ import serverConfig from "./config";const ROOT_PATH = path.join(serverConfig.dataDir, "assets");-export const SUPPORTED_ASSET_TYPES = new Set([+// The assets that we allow the users to upload+export const SUPPORTED_UPLOAD_ASSET_TYPES = new Set(["image/jpeg","image/png","image/webp","application/pdf",]);+// The assets that we support saving in the asset db+export const SUPPORTED_ASSET_TYPES = new Set([+ ...SUPPORTED_UPLOAD_ASSET_TYPES,+ "text/html",+]);+function getAssetDir(userId: string, assetId: string) {return path.join(ROOT_PATH, userId, assetId);}@@ -52,6 +59,32 @@ export async function saveAsset({]);}+export async function saveAssetFromFile({+ userId,+ assetId,+ assetPath,+ metadata,+}: {+ userId: string;+ assetId: string;+ assetPath: string;+ metadata: z.infer<typeof zAssetMetadataSchema>;+}) {+ if (!SUPPORTED_ASSET_TYPES.has(metadata.contentType)) {+ throw new Error("Unsupported asset type");+ }+ const assetDir = getAssetDir(userId, assetId);+ await fs.promises.mkdir(assetDir, { recursive: true });++ await Promise.all([+ fs.promises.rename(assetPath, path.join(assetDir, "asset.bin")),+ fs.promises.writeFile(+ path.join(assetDir, "metadata.json"),+ JSON.stringify(metadata),+ ),+ ]);+}+export async function readAsset({userId,assetId,diff --git a/packages/shared/config.ts b/packages/shared/config.tsindex 8bb4e830..2c739a0c 100644--- a/packages/shared/config.ts+++ b/packages/shared/config.ts@@ -29,6 +29,7 @@ const allEnv = z.object({CRAWLER_DOWNLOAD_BANNER_IMAGE: stringBool("true"),CRAWLER_STORE_SCREENSHOT: stringBool("true"),CRAWLER_FULL_PAGE_SCREENSHOT: stringBool("false"),+ CRAWLER_FULL_PAGE_ARCHIVE: stringBool("false"),MEILI_ADDR: z.string().optional(),MEILI_MASTER_KEY: z.string().default(""),LOG_LEVEL: z.string().default("debug"),@@ -74,6 +75,7 @@ const serverConfigSchema = allEnv.transform((val) => {downloadBannerImage: val.CRAWLER_DOWNLOAD_BANNER_IMAGE,storeScreenshot: val.CRAWLER_STORE_SCREENSHOT,fullPageScreenshot: val.CRAWLER_FULL_PAGE_SCREENSHOT,+ fullPageArchive: val.CRAWLER_FULL_PAGE_ARCHIVE,},meilisearch: val.MEILI_ADDR? {diff --git a/packages/shared/types/bookmarks.ts b/packages/shared/types/bookmarks.tsindex 10dba0c8..06cd632e 100644--- a/packages/shared/types/bookmarks.ts+++ b/packages/shared/types/bookmarks.ts@@ -12,6 +12,7 @@ export const zBookmarkedLinkSchema = z.object({imageUrl: z.string().url().nullish(),imageAssetId: z.string().nullish(),screenshotAssetId: z.string().nullish(),+ fullPageArchiveAssetId: z.string().nullish(),favicon: z.string().url().nullish(),htmlContent: z.string().nullish(),crawledAt: z.date().nullish(),diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.tsindex 0a9747c9..5f53dd16 100644--- a/packages/trpc/routers/bookmarks.ts+++ b/packages/trpc/routers/bookmarks.ts@@ -146,6 +146,9 @@ async function cleanupAssetForBookmark(if (bookmark.link.imageAssetId) {assetIds.push(bookmark.link.imageAssetId);}+ if (bookmark.link.fullPageArchiveAssetId) {+ assetIds.push(bookmark.link.fullPageArchiveAssetId);+ }}await Promise.all(assetIds.map((assetId) =>diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 8ab67bfd..6bea8ddb 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -662,6 +662,9 @@ importers:drizzle-orm:specifier: ^0.29.4+ execa:+ specifier: ^9.1.0+ version: 9.1.0jsdom:specifier: ^24.0.0version: 24.0.0@@ -3736,6 +3739,9 @@ packages:cpu: [x64]os: [win32]+ '@sec-ant/[email protected]':+ resolution: {integrity: sha512-831qok9r2t8AlxLko40y2ebgSDhenenCatLVeW/uBtnHPyhHOvG0C7TvfgecV+wHzIm5KUICgzmVpWS+IMEAeg==}+'@segment/[email protected]':resolution: {integrity: sha512-ZMCSfztDBqwotkl848ODgVcAmN4OItEWDCkshcKz0/W6gGSQayuuCtWV/MlodFivAZD793d6UgANd6wCXUfrIw==}@@ -3759,6 +3765,10 @@ packages:resolution: {integrity: sha512-TV7t8GKYaJWsn00tFDqBw8+Uqmr8A0fRU1tvTQhyZzGv0sJCGRQL3JGMI3ucuKo3XIZdUP+Lx7/gh2t3lewy7g==}engines: {node: '>=14.16'}+ '@sindresorhus/[email protected]':+ resolution: {integrity: sha512-tlqY9xq5ukxTUZBmoOp+m61cqwQD5pHJtFY3Mn8CA8ps6yghLH/Hw8UPdqg4OLmFW3IFlcXnQNmo/dh8HzXYIQ==}+ engines: {node: '>=18'}+'@sinonjs/[email protected]':resolution: {integrity: sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==}@@ -6517,6 +6527,10 @@ packages:resolution: {integrity: sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==}engines: {node: '>=16.17'}+ resolution: {integrity: sha512-lSgHc4Elo2m6bUDhc3Hl/VxvUDJdQWI40RZ4KMY9bKRc+hgMOT7II/JjbNDhI8VnMtrCb7U/fhpJIkLORZozWw==}+ engines: {node: '>=18'}+resolution: {integrity: sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==}engines: {node: '>=6'}@@ -6768,6 +6782,10 @@ packages:resolution: {integrity: sha512-e6eB7zN6UBSwGVwrbWVH+gdLnkW9WwHhmq2YDK1Sh30pzx1onRVGBvogTlUeWxwTa+L86NYdo4hFkh7O8ZjSnA==}+ resolution: {integrity: sha512-d+l3qxjSesT4V7v2fh+QnmFnUWv9lSpjarhShNTgBOfA0ttejbQUAlHLitbjkoRiDulW0OPoQPYIGhIC8ohejg==}+ engines: {node: '>=18'}+resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==}engines: {node: ^10.12.0 || >=12.0.0}@@ -7048,6 +7066,10 @@ packages:resolution: {integrity: sha512-VaUJspBffn/LMCJVoMvSAdmscJyS1auj5Zulnn5UoYcY531UWmdwhRWkcGKnGU93m5HSXP9LP2usOryrBtQowA==}engines: {node: '>=16'}+ resolution: {integrity: sha512-kVCxPF3vQM/N0B1PmoqVUqgHP+EeVjmZSQn+1oCRPxd2P21P2F19lIgbR3HBosbB1PUhOAoctJnfEn2GbN2eZA==}+ engines: {node: '>=18'}+resolution: {integrity: sha512-g0QYk1dZBxGwk+Ngc+ltRH2IBp2f7zBkBMBJZCDerh6EhlhSR6+9irMCuT/09zD6qkarHUSn529sK/yL4S27mg==}engines: {node: '>= 0.4'}@@ -7388,6 +7410,10 @@ packages:resolution: {integrity: sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==}engines: {node: '>=16.17.0'}+ resolution: {integrity: sha512-74kytxOUSvNbjrT9KisAbaTZ/eJwD/LrbM/kh5j0IhPuJzwuA19dWvniFGwBzN9rVjg+O/e+F310PjObDXS+9Q==}+ engines: {node: '>=18.18.0'}+resolution: {integrity: sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==}@@ -7769,6 +7795,10 @@ packages:resolution: {integrity: sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==}engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}+ resolution: {integrity: sha512-Dnz92NInDqYckGEUJv689RbRiTSEHCQ7wOVeALbkOz999YpqT46yMRIGtSNl2iCL1waAZSx40+h59NV/EwzV/A==}+ engines: {node: '>=18'}+resolution: {integrity: sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==}engines: {node: '>= 0.4'}@@ -7788,6 +7818,10 @@ packages:resolution: {integrity: sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==}engines: {node: '>=10'}+ resolution: {integrity: sha512-FRdAyx5lusK1iHG0TWpVtk9+1i+GjrzRffhDg4ovQ7mcidMQ6mj+MhKPmvh7Xwyv5gIS06ns49CA7Sqg7lC22Q==}+ engines: {node: '>=18'}+resolution: {integrity: sha512-kNciklu//Ki8BUmRseLTfG/WW55qDHavf3MKUic8wvXR3d7etbSMoQPTpjvDeLVekESSgJM4AG+BESIKU02u3A==}engines: {node: '>= 4'}@@ -9361,6 +9395,10 @@ packages:resolution: {integrity: sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==}engines: {node: '>=8'}+ resolution: {integrity: sha512-TXfryirbmq34y8QBwgqCVLi+8oA3oWx2eAnSn62ITyEhEYaWRlVZ2DvMM9eZbMs/RfxPu/PK/aBLyGj4IrqMHw==}+ engines: {node: '>=18'}+resolution: {integrity: sha512-twN+njEipszzlMJd4ONUYgSfZPDxgHhT9Ahed5uTigpQn90FggW4SA/AIPq/6a149fTbE9qBEcSwE3FAEp6wQQ==}@@ -9909,6 +9947,10 @@ packages:resolution: {integrity: sha512-WuxUnVtlWL1OfZFQFuqvnvs6MiAGk9UNsBostyBOB0Is9wb5uRESevA6rnl/rkksXaGX3GzZhPup5d6Vp1nFew==}+ resolution: {integrity: sha512-E9e9HJ9R9NasGOgPaPE8VMeiPKAyWR5jcFpNnwIejslIhWqdqOrb2wShBsncMPUb+BcCd2OPYfh7p2W6oemTng==}+ engines: {node: '>=18'}+resolution: {integrity: sha512-28iF6xPQrP8Oa6uxE6a1biz+lWeTOAPKggvjB8HAs6nVMKZwf5bG++632Dx614hIWgUPkgivRfG+a8uAXGTIbA==}engines: {node: '>=4'}@@ -10081,6 +10123,7 @@ packages:resolution: {integrity: sha512-GC+tyjzYKjaNjhlDAuqRgDM+IOsqOG75Da4L28G4eULNLLxKDt+79x2OOSQ47HheJBgGq7ATSExNE6gayxP6cg==}engines: {node: '>=18'}+ deprecated: < 22.5.0 is no longer supportedhasBin: true@@ -11112,6 +11155,10 @@ packages:resolution: {integrity: sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==}engines: {node: '>=12'}+ resolution: {integrity: sha512-aulFJcD6YK8V1G7iRB5tigAP4TsHBZZrOV8pjV++zdUwmeV8uzbY7yn6h9MswN62adStNZFuCIx4haBnRuMDaw==}+ engines: {node: '>=18'}+resolution: {integrity: sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==}engines: {node: '>=8'}@@ -12311,6 +12358,10 @@ packages:resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==}engines: {node: '>=12.20'}+ resolution: {integrity: sha512-Ct97huExsu7cWeEjmrXlofevF8CvzUglJ4iGUet5B8xn1oumtAZBpHU4GzYuoE6PVqcZ5hghtBrSlhwHuR1Jmw==}+ engines: {node: '>=18'}+resolution: {integrity: sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==}@@ -17457,6 +17508,9 @@ snapshots:dev: trueoptional: true+ '@sec-ant/[email protected]':+ dev: false+'@segment/[email protected]':dependencies:component-type: 1.2.2@@ -17479,6 +17533,9 @@ snapshots:'@sindresorhus/[email protected]':dev: false+ '@sindresorhus/[email protected]':+ dev: false+'@sinonjs/[email protected]':dependencies:type-detect: 4.0.8@@ -21267,6 +21324,22 @@ snapshots:strip-final-newline: 3.0.0dev: true+ dependencies:+ '@sindresorhus/merge-streams': 4.0.0+ cross-spawn: 7.0.3+ figures: 6.1.0+ get-stream: 9.0.1+ human-signals: 7.0.0+ is-plain-obj: 4.1.0+ is-stream: 4.0.1+ npm-run-path: 5.3.0+ pretty-ms: 9.0.0+ signal-exit: 4.1.0+ strip-final-newline: 4.0.0+ yoctocolors: 2.0.2+ dev: false+dev: false@@ -21690,6 +21763,11 @@ snapshots:dev: false+ dependencies:+ is-unicode-supported: 2.0.0+ dev: false+dependencies:flat-cache: 3.2.0@@ -22031,6 +22109,12 @@ snapshots:dev: true+ dependencies:+ '@sec-ant/readable-stream': 0.4.1+ is-stream: 4.0.1+ dev: false+dependencies:call-bind: 1.0.7@@ -22589,6 +22673,9 @@ snapshots:dev: true+ dev: false+dependencies:ms: 2.1.3@@ -22958,6 +23045,9 @@ snapshots:dev: true+ dev: false+dependencies:has-tostringtag: 1.0.2@@ -22976,6 +23066,9 @@ snapshots:dev: false+ dev: false+dependencies:parse-uri: 1.0.9@@ -25069,7 +25162,6 @@ snapshots:dependencies:path-key: 4.0.0- dev: truedependencies:@@ -25417,6 +25509,9 @@ snapshots:lines-and-columns: 1.2.4dev: false+ dev: false+dev: false@@ -25470,8 +25565,7 @@ snapshots:- dev: true+ [email protected]: {}@@ -25955,6 +26049,11 @@ snapshots:dev: false+ dependencies:+ parse-ms: 4.0.0+ dev: false+dev: false@@ -27715,6 +27814,9 @@ snapshots:dev: true+ dev: false+dependencies:min-indent: 1.0.1@@ -29282,6 +29384,9 @@ snapshots:+ dev: false+