A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
feat: add synchronized reading progress for bookmarks (#2302)
Evan Simkowitzfff0a280bc83
diff --git a/apps/mobile/components/bookmarks/BookmarkHtmlHighlighterDom.tsx b/apps/mobile/components/bookmarks/BookmarkHtmlHighlighterDom.tsxindex adf59911..10965307 100644--- a/apps/mobile/components/bookmarks/BookmarkHtmlHighlighterDom.tsx+++ b/apps/mobile/components/bookmarks/BookmarkHtmlHighlighterDom.tsx@@ -4,6 +4,7 @@ import "@/globals.css";import type { Highlight } from "@karakeep/shared-react/components/BookmarkHtmlHighlighter";import BookmarkHTMLHighlighter from "@karakeep/shared-react/components/BookmarkHtmlHighlighter";+import ScrollProgressTracker from "@karakeep/shared-react/components/ScrollProgressTracker";export default function BookmarkHtmlHighlighterDom({htmlContent,@@ -13,6 +14,11 @@ export default function BookmarkHtmlHighlighterDom({onHighlight,onUpdateHighlight,onDeleteHighlight,+ readingProgressOffset,+ readingProgressAnchor,+ restoreReadingPosition,+ onSavePosition,+ onScrollPositionChange,}: {htmlContent: string;contentStyle?: React.CSSProperties;@@ -21,19 +27,42 @@ export default function BookmarkHtmlHighlighterDom({onHighlight?: (highlight: Highlight) => void;onUpdateHighlight?: (highlight: Highlight) => void;onDeleteHighlight?: (highlight: Highlight) => void;+ readingProgressOffset?: number | null;+ readingProgressAnchor?: string | null;+ restoreReadingPosition?: boolean;+ onSavePosition?: (position: {+ offset: number;+ anchor: string;+ percent: number;+ }) => void;+ onScrollPositionChange?: (position: {+ offset: number;+ anchor: string;+ percent: number;+ }) => void;dom?: import("expo/dom").DOMProps;}) {return (<div style={{ maxWidth: "100vw", overflowX: "hidden" }}>- <BookmarkHTMLHighlighter- htmlContent={htmlContent}- highlights={highlights}- readOnly={readOnly}- onHighlight={onHighlight}- onUpdateHighlight={onUpdateHighlight}- onDeleteHighlight={onDeleteHighlight}- style={contentStyle}- />+ <ScrollProgressTracker+ onSavePosition={onSavePosition}+ onScrollPositionChange={onScrollPositionChange}+ restorePosition={restoreReadingPosition}+ readingProgressOffset={readingProgressOffset}+ readingProgressAnchor={readingProgressAnchor}+ showProgressBar+ progressBarStyle={{ position: "fixed" }}+ >+ <BookmarkHTMLHighlighter+ htmlContent={htmlContent}+ highlights={highlights}+ readOnly={readOnly}+ onHighlight={onHighlight}+ onUpdateHighlight={onUpdateHighlight}+ onDeleteHighlight={onDeleteHighlight}+ style={contentStyle}+ />+ </ScrollProgressTracker></div>);}diff --git a/apps/mobile/components/bookmarks/BookmarkLinkPreview.tsx b/apps/mobile/components/bookmarks/BookmarkLinkPreview.tsxindex 32c21a79..80a918a9 100644--- a/apps/mobile/components/bookmarks/BookmarkLinkPreview.tsx+++ b/apps/mobile/components/bookmarks/BookmarkLinkPreview.tsx@@ -1,5 +1,5 @@import { useState } from "react";-import { Pressable, View } from "react-native";+import { Pressable, TouchableOpacity, View } from "react-native";import ImageView from "react-native-image-viewing";import WebView from "react-native-webview";import { WebViewSourceUri } from "react-native-webview/lib/WebViewTypes";@@ -8,12 +8,14 @@ import { useAssetUrl } from "@/lib/hooks";import { useReaderSettings, WEBVIEW_FONT_FAMILIES } from "@/lib/readerSettings";import { useColorScheme } from "@/lib/useColorScheme";import { useQuery } from "@tanstack/react-query";+import { BookOpen, X } from "lucide-react-native";import {useCreateHighlight,useDeleteHighlight,useUpdateHighlight,} from "@karakeep/shared-react/hooks/highlights";+import { useReadingProgress } from "@karakeep/shared-react/hooks/reading-progress";import { useTRPC } from "@karakeep/shared-react/trpc";import { BookmarkTypes, ZBookmark } from "@karakeep/shared/types/bookmarks";@@ -96,6 +98,20 @@ export function BookmarkLinkReaderPreview({const { mutate: updateHighlight } = useUpdateHighlight();const { mutate: deleteHighlight } = useDeleteHighlight();+ const {+ showBanner,+ bannerPercent,+ onContinue,+ onDismiss,+ restorePosition,+ readingProgressOffset,+ readingProgressAnchor,+ onSavePosition,+ onScrollPositionChange,+ } = useReadingProgress({+ bookmarkId: bookmark.id,+ });+if (isLoading) {return <FullPageSpinner />;}@@ -119,10 +135,36 @@ export function BookmarkLinkReaderPreview({return (<View className="flex-1 bg-background">+ {showBanner && (+ <View className="flex-row items-center gap-2 border-b border-border bg-background px-4 py-2">+ <BookOpen size={16} className="text-muted-foreground" />+ <Text className="flex-1 text-sm text-muted-foreground">+ {bannerPercent && bannerPercent > 0+ ? `Continue where you left off (${bannerPercent}%)`+ : "Continue where you left off"}+ </Text>+ <TouchableOpacity+ onPress={onContinue}+ className="rounded-md bg-primary px-3 py-1"+ >+ <Text className="text-xs font-medium text-primary-foreground">+ Continue+ </Text>+ </TouchableOpacity>+ <TouchableOpacity onPress={onDismiss} className="p-1">+ <X size={14} className="text-muted-foreground" />+ </TouchableOpacity>+ </View>+ )}<BookmarkHtmlHighlighterDomhtmlContent={bookmarkWithContent.content.htmlContent ?? ""}contentStyle={contentStyle}highlights={highlights?.highlights ?? []}+ readingProgressOffset={readingProgressOffset}+ readingProgressAnchor={readingProgressAnchor}+ restoreReadingPosition={restorePosition}+ onSavePosition={onSavePosition}+ onScrollPositionChange={onScrollPositionChange}onHighlight={(h) =>createHighlight({startOffset: h.startOffset,diff --git a/apps/web/app/dashboard/preview/[bookmarkId]/page.tsx b/apps/web/app/dashboard/preview/[bookmarkId]/page.tsxindex ea509207..2d4c42bf 100644--- a/apps/web/app/dashboard/preview/[bookmarkId]/page.tsx+++ b/apps/web/app/dashboard/preview/[bookmarkId]/page.tsx@@ -22,7 +22,7 @@ export default async function BookmarkPreviewPage(props: {}return (- <div className="max-h-screen">+ <div className="h-[calc(100dvh-theme(spacing.16)-theme(spacing.8))] overflow-hidden"><BookmarkPreview bookmarkId={bookmark.id} initialData={bookmark} /></div>);diff --git a/apps/web/app/reader/[bookmarkId]/page.tsx b/apps/web/app/reader/[bookmarkId]/page.tsxindex ac64c9af..7efa4110 100644--- a/apps/web/app/reader/[bookmarkId]/page.tsx+++ b/apps/web/app/reader/[bookmarkId]/page.tsx@@ -135,6 +135,7 @@ export default function ReaderViewPage() {}}bookmarkId={bookmarkId}readOnly={!isOwner}+ progressBarStyle={{ position: "fixed", top: "3.5rem" }}/></div></Suspense>diff --git a/apps/web/components/dashboard/preview/BookmarkPreview.tsx b/apps/web/components/dashboard/preview/BookmarkPreview.tsxindex f1ed039c..6f41a3b1 100644--- a/apps/web/components/dashboard/preview/BookmarkPreview.tsx+++ b/apps/web/components/dashboard/preview/BookmarkPreview.tsx@@ -228,16 +228,13 @@ export default function BookmarkPreview({{detailsSection}</div></div>-{/* Render tabbed layout for narrow/vertical screens */}<Tabsvalue={activeTab}onValueChange={setActiveTab}className="flex h-full w-full flex-col overflow-hidden lg:hidden">- <TabsList- className={`sticky top-0 z-10 grid h-auto w-full grid-cols-2`}- >+ <TabsList className="sticky top-0 z-10 grid h-auto w-full grid-cols-2"><TabsTrigger value="content">{t("preview.tabs.content")}</TabsTrigger><TabsTrigger value="details">{t("preview.tabs.details")}</TabsTrigger></TabsList>diff --git a/apps/web/components/dashboard/preview/LinkContentSection.tsx b/apps/web/components/dashboard/preview/LinkContentSection.tsxindex df1445a3..c8d2c6be 100644--- a/apps/web/components/dashboard/preview/LinkContentSection.tsx+++ b/apps/web/components/dashboard/preview/LinkContentSection.tsx@@ -285,7 +285,7 @@ export default function LinkContentSection({</Tooltip>)}</div>- <div className="h-full w-full min-w-0 flex-1">{content}</div>+ <div className="min-h-0 w-full min-w-0 flex-1">{content}</div></div>);}diff --git a/apps/web/components/dashboard/preview/ReaderView.tsx b/apps/web/components/dashboard/preview/ReaderView.tsxindex 9adac916..49976249 100644--- a/apps/web/components/dashboard/preview/ReaderView.tsx+++ b/apps/web/components/dashboard/preview/ReaderView.tsx@@ -5,24 +5,30 @@ import { useQuery } from "@tanstack/react-query";import { FileX } from "lucide-react";import BookmarkHTMLHighlighter from "@karakeep/shared-react/components/BookmarkHtmlHighlighter";+import ScrollProgressTracker from "@karakeep/shared-react/components/ScrollProgressTracker";import {useCreateHighlight,useDeleteHighlight,useUpdateHighlight,} from "@karakeep/shared-react/hooks/highlights";+import { useReadingProgress } from "@karakeep/shared-react/hooks/reading-progress";import { useTRPC } from "@karakeep/shared-react/trpc";import { BookmarkTypes } from "@karakeep/shared/types/bookmarks";+import ReadingProgressBanner from "./ReadingProgressBanner";+export default function ReaderView({bookmarkId,className,style,readOnly,+ progressBarStyle,}: {bookmarkId: string;className?: string;style?: React.CSSProperties;readOnly: boolean;+ progressBarStyle?: React.CSSProperties;}) {const { t } = useTranslation();const api = useTRPC();@@ -46,6 +52,20 @@ export default function ReaderView({),);+ const {+ showBanner,+ bannerPercent,+ onContinue,+ onDismiss,+ restorePosition,+ readingProgressOffset,+ readingProgressAnchor,+ onSavePosition,+ onScrollPositionChange,+ } = useReadingProgress({+ bookmarkId,+ });+const { mutate: createHighlight } = useCreateHighlight({onSuccess: () => {toast({@@ -113,35 +133,52 @@ export default function ReaderView({);} else {content = (- <BookmarkHTMLHighlighter- className={className}- style={style}- htmlContent={cachedContent || ""}- highlights={highlights?.highlights ?? []}- readOnly={readOnly}- onDeleteHighlight={(h) =>- deleteHighlight({- highlightId: h.id,- })- }- onUpdateHighlight={(h) =>- updateHighlight({- highlightId: h.id,- color: h.color,- note: h.note,- })- }- onHighlight={(h) =>- createHighlight({- startOffset: h.startOffset,- endOffset: h.endOffset,- color: h.color,- bookmarkId,- text: h.text,- note: h.note ?? null,- })- }- />+ <ScrollProgressTracker+ onSavePosition={onSavePosition}+ onScrollPositionChange={onScrollPositionChange}+ restorePosition={restorePosition}+ readingProgressOffset={readingProgressOffset}+ readingProgressAnchor={readingProgressAnchor}+ showProgressBar+ progressBarStyle={progressBarStyle}+ >+ {showBanner && (+ <ReadingProgressBanner+ percent={bannerPercent}+ onContinue={onContinue}+ onDismiss={onDismiss}+ />+ )}+ <BookmarkHTMLHighlighter+ className={className}+ style={style}+ htmlContent={cachedContent || ""}+ highlights={highlights?.highlights ?? []}+ readOnly={readOnly}+ onDeleteHighlight={(h) =>+ deleteHighlight({+ highlightId: h.id,+ })+ }+ onUpdateHighlight={(h) =>+ updateHighlight({+ highlightId: h.id,+ color: h.color,+ note: h.note,+ })+ }+ onHighlight={(h) =>+ createHighlight({+ startOffset: h.startOffset,+ endOffset: h.endOffset,+ color: h.color,+ bookmarkId,+ text: h.text,+ note: h.note ?? null,+ })+ }+ />+ </ScrollProgressTracker>);}return content;diff --git a/apps/web/components/dashboard/preview/ReadingProgressBanner.tsx b/apps/web/components/dashboard/preview/ReadingProgressBanner.tsxnew file mode 100644index 00000000..6465d462--- /dev/null+++ b/apps/web/components/dashboard/preview/ReadingProgressBanner.tsx@@ -0,0 +1,43 @@+"use client";++import { useTranslation } from "@/lib/i18n/client";+import { BookOpen, X } from "lucide-react";++export default function ReadingProgressBanner({+ percent,+ onContinue,+ onDismiss,+}: {+ percent?: number | null;+ onContinue: () => void;+ onDismiss: () => void;+}) {+ const { t } = useTranslation();++ const message =+ percent && percent > 0+ ? t("preview.continue_reading_percent", { percent })+ : t("preview.continue_reading");++ return (+ <div className="sticky top-0 z-10 flex justify-center px-4 py-3">+ <div className="flex items-center gap-3 rounded-full border border-border/60 bg-background/80 px-4 py-2 text-sm shadow-sm backdrop-blur-md">+ <BookOpen className="h-4 w-4 shrink-0 text-muted-foreground" />+ <span className="truncate text-muted-foreground">{message}</span>+ <button+ onClick={onContinue}+ className="shrink-0 rounded-full bg-foreground px-3 py-1 text-xs font-medium text-background transition-opacity hover:opacity-80"+ >+ {t("preview.continue_button")}+ </button>+ <button+ onClick={onDismiss}+ className="shrink-0 rounded-full p-1 text-muted-foreground transition-colors hover:text-foreground"+ aria-label="Dismiss"+ >+ <X className="h-3.5 w-3.5" />+ </button>+ </div>+ </div>+ );+}diff --git a/apps/web/lib/i18n/locales/en/translation.json b/apps/web/lib/i18n/locales/en/translation.jsonindex 12d7a082..03206c82 100644--- a/apps/web/lib/i18n/locales/en/translation.json+++ b/apps/web/lib/i18n/locales/en/translation.json@@ -834,6 +834,9 @@"fetch_error_title": "Content Unavailable","fetch_error_description": "We couldn't fetch the content for this link. The page may be protected, require authentication, or be temporarily unavailable.","crawling_in_progress": "Fetching page content…",+ "continue_reading": "Continue where you left off",+ "continue_reading_percent": "Continue where you left off ({{percent}}%)",+ "continue_button": "Continue","tabs": {"content": "Content","details": "Details"diff --git a/packages/db/drizzle/0080_user_reading_progress.sql b/packages/db/drizzle/0080_user_reading_progress.sqlnew file mode 100644index 00000000..9b675dab--- /dev/null+++ b/packages/db/drizzle/0080_user_reading_progress.sql@@ -0,0 +1,15 @@+CREATE TABLE `userReadingProgress` (+ `id` text PRIMARY KEY NOT NULL,+ `bookmarkId` text NOT NULL,+ `userId` text NOT NULL,+ `readingProgressOffset` integer NOT NULL,+ `readingProgressAnchor` text,+ `readingProgressPercent` integer,+ `modifiedAt` integer,+ FOREIGN KEY (`bookmarkId`) REFERENCES `bookmarks`(`id`) ON UPDATE no action ON DELETE cascade,+ FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade+);+--> statement-breakpoint+CREATE INDEX `userReadingProgress_bookmarkId_idx` ON `userReadingProgress` (`bookmarkId`);--> statement-breakpoint+CREATE INDEX `userReadingProgress_userId_idx` ON `userReadingProgress` (`userId`);--> statement-breakpoint+CREATE UNIQUE INDEX `userReadingProgress_bookmarkId_userId_unique` ON `userReadingProgress` (`bookmarkId`,`userId`);\ No newline at end of filediff --git a/packages/db/drizzle/meta/0080_snapshot.json b/packages/db/drizzle/meta/0080_snapshot.jsonnew file mode 100644index 00000000..35c906ce--- /dev/null+++ b/packages/db/drizzle/meta/0080_snapshot.json@@ -0,0 +1,3349 @@+{+ "version": "6",+ "dialect": "sqlite",+ "id": "cda8a968-ca40-4ea7-bd65-9a004ca16ae5",+ "prevId": "eefce4a3-19af-48d5-a588-e8f2a538fa39",+ "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": {},+ "checkConstraints": {}+ },+ "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+ },+ "lastUsedAt": {+ "name": "lastUsedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "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": {},+ "checkConstraints": {}+ },+ "assets": {+ "name": "assets",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "assetType": {+ "name": "assetType",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "size": {+ "name": "size",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 0+ },+ "contentType": {+ "name": "contentType",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "fileName": {+ "name": "fileName",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "bookmarkId": {+ "name": "bookmarkId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "assets_bookmarkId_idx": {+ "name": "assets_bookmarkId_idx",+ "columns": [+ "bookmarkId"+ ],+ "isUnique": false+ },+ "assets_assetType_idx": {+ "name": "assets_assetType_idx",+ "columns": [+ "assetType"+ ],+ "isUnique": false+ },+ "assets_userId_idx": {+ "name": "assets_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "assets_bookmarkId_bookmarks_id_fk": {+ "name": "assets_bookmarkId_bookmarks_id_fk",+ "tableFrom": "assets",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "bookmarkId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "assets_userId_user_id_fk": {+ "name": "assets_userId_user_id_fk",+ "tableFrom": "assets",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "backups": {+ "name": "backups",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "assetId": {+ "name": "assetId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "size": {+ "name": "size",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "bookmarkCount": {+ "name": "bookmarkCount",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'pending'"+ },+ "errorMessage": {+ "name": "errorMessage",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "backups_userId_idx": {+ "name": "backups_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "backups_createdAt_idx": {+ "name": "backups_createdAt_idx",+ "columns": [+ "createdAt"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "backups_userId_user_id_fk": {+ "name": "backups_userId_user_id_fk",+ "tableFrom": "backups",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "backups_assetId_assets_id_fk": {+ "name": "backups_assetId_assets_id_fk",+ "tableFrom": "backups",+ "tableTo": "assets",+ "columnsFrom": [+ "assetId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "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+ },+ "sourceUrl": {+ "name": "sourceUrl",+ "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": {},+ "checkConstraints": {}+ },+ "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+ },+ "author": {+ "name": "author",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "publisher": {+ "name": "publisher",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "datePublished": {+ "name": "datePublished",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "dateModified": {+ "name": "dateModified",+ "type": "integer",+ "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+ },+ "htmlContent": {+ "name": "htmlContent",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "contentAssetId": {+ "name": "contentAssetId",+ "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'"+ },+ "crawlStatusCode": {+ "name": "crawlStatusCode",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": 200+ }+ },+ "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": {},+ "checkConstraints": {}+ },+ "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+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "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+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "query": {+ "name": "query",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "parentId": {+ "name": "parentId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "rssToken": {+ "name": "rssToken",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "public": {+ "name": "public",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ }+ },+ "indexes": {+ "bookmarkLists_userId_idx": {+ "name": "bookmarkLists_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "bookmarkLists_userId_id_idx": {+ "name": "bookmarkLists_userId_id_idx",+ "columns": [+ "userId",+ "id"+ ],+ "isUnique": true+ }+ },+ "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": {},+ "checkConstraints": {}+ },+ "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+ },+ "normalizedName": {+ "name": "normalizedName",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "generated": {+ "as": "(lower(replace(replace(replace(\"name\", ' ', ''), '-', ''), '_', '')))",+ "type": "virtual"+ }+ },+ "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_normalizedName_idx": {+ "name": "bookmarkTags_normalizedName_idx",+ "columns": [+ "normalizedName"+ ],+ "isUnique": false+ },+ "bookmarkTags_userId_name_unique": {+ "name": "bookmarkTags_userId_name_unique",+ "columns": [+ "userId",+ "name"+ ],+ "isUnique": true+ },+ "bookmarkTags_userId_id_idx": {+ "name": "bookmarkTags_userId_id_idx",+ "columns": [+ "userId",+ "id"+ ],+ "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": {},+ "checkConstraints": {}+ },+ "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+ },+ "sourceUrl": {+ "name": "sourceUrl",+ "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": {},+ "checkConstraints": {}+ },+ "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+ },+ "modifiedAt": {+ "name": "modifiedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "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'"+ },+ "summarizationStatus": {+ "name": "summarizationStatus",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'pending'"+ },+ "summary": {+ "name": "summary",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "note": {+ "name": "note",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "source": {+ "name": "source",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "bookmarks_userId_idx": {+ "name": "bookmarks_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "bookmarks_createdAt_idx": {+ "name": "bookmarks_createdAt_idx",+ "columns": [+ "createdAt"+ ],+ "isUnique": false+ },+ "bookmarks_userId_createdAt_id_idx": {+ "name": "bookmarks_userId_createdAt_id_idx",+ "columns": [+ "userId",+ "createdAt",+ "id"+ ],+ "isUnique": false+ },+ "bookmarks_userId_archived_createdAt_id_idx": {+ "name": "bookmarks_userId_archived_createdAt_id_idx",+ "columns": [+ "userId",+ "archived",+ "createdAt",+ "id"+ ],+ "isUnique": false+ },+ "bookmarks_userId_favourited_createdAt_id_idx": {+ "name": "bookmarks_userId_favourited_createdAt_id_idx",+ "columns": [+ "userId",+ "favourited",+ "createdAt",+ "id"+ ],+ "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": {},+ "checkConstraints": {}+ },+ "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+ },+ "listMembershipId": {+ "name": "listMembershipId",+ "type": "text",+ "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+ },+ "bookmarksInLists_listId_bookmarkId_idx": {+ "name": "bookmarksInLists_listId_bookmarkId_idx",+ "columns": [+ "listId",+ "bookmarkId"+ ],+ "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"+ },+ "bookmarksInLists_listMembershipId_listCollaborators_id_fk": {+ "name": "bookmarksInLists_listMembershipId_listCollaborators_id_fk",+ "tableFrom": "bookmarksInLists",+ "tableTo": "listCollaborators",+ "columnsFrom": [+ "listMembershipId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "bookmarksInLists_bookmarkId_listId_pk": {+ "columns": [+ "bookmarkId",+ "listId"+ ],+ "name": "bookmarksInLists_bookmarkId_listId_pk"+ }+ },+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "config": {+ "name": "config",+ "columns": {+ "key": {+ "name": "key",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "value": {+ "name": "value",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "customPrompts": {+ "name": "customPrompts",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "text": {+ "name": "text",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "enabled": {+ "name": "enabled",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "appliesTo": {+ "name": "appliesTo",+ "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": {+ "customPrompts_userId_idx": {+ "name": "customPrompts_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "customPrompts_userId_user_id_fk": {+ "name": "customPrompts_userId_user_id_fk",+ "tableFrom": "customPrompts",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "highlights": {+ "name": "highlights",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "bookmarkId": {+ "name": "bookmarkId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "startOffset": {+ "name": "startOffset",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "endOffset": {+ "name": "endOffset",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "color": {+ "name": "color",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'yellow'"+ },+ "text": {+ "name": "text",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "note": {+ "name": "note",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "highlights_bookmarkId_idx": {+ "name": "highlights_bookmarkId_idx",+ "columns": [+ "bookmarkId"+ ],+ "isUnique": false+ },+ "highlights_userId_idx": {+ "name": "highlights_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "highlights_bookmarkId_bookmarks_id_fk": {+ "name": "highlights_bookmarkId_bookmarks_id_fk",+ "tableFrom": "highlights",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "bookmarkId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "highlights_userId_user_id_fk": {+ "name": "highlights_userId_user_id_fk",+ "tableFrom": "highlights",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "importSessionBookmarks": {+ "name": "importSessionBookmarks",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "importSessionId": {+ "name": "importSessionId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "bookmarkId": {+ "name": "bookmarkId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "importSessionBookmarks_sessionId_idx": {+ "name": "importSessionBookmarks_sessionId_idx",+ "columns": [+ "importSessionId"+ ],+ "isUnique": false+ },+ "importSessionBookmarks_bookmarkId_idx": {+ "name": "importSessionBookmarks_bookmarkId_idx",+ "columns": [+ "bookmarkId"+ ],+ "isUnique": false+ },+ "importSessionBookmarks_importSessionId_bookmarkId_unique": {+ "name": "importSessionBookmarks_importSessionId_bookmarkId_unique",+ "columns": [+ "importSessionId",+ "bookmarkId"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "importSessionBookmarks_importSessionId_importSessions_id_fk": {+ "name": "importSessionBookmarks_importSessionId_importSessions_id_fk",+ "tableFrom": "importSessionBookmarks",+ "tableTo": "importSessions",+ "columnsFrom": [+ "importSessionId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "importSessionBookmarks_bookmarkId_bookmarks_id_fk": {+ "name": "importSessionBookmarks_bookmarkId_bookmarks_id_fk",+ "tableFrom": "importSessionBookmarks",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "bookmarkId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "importSessions": {+ "name": "importSessions",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "message": {+ "name": "message",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "rootListId": {+ "name": "rootListId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'staging'"+ },+ "lastProcessedAt": {+ "name": "lastProcessedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "modifiedAt": {+ "name": "modifiedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "importSessions_userId_idx": {+ "name": "importSessions_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "importSessions_status_idx": {+ "name": "importSessions_status_idx",+ "columns": [+ "status"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "importSessions_userId_user_id_fk": {+ "name": "importSessions_userId_user_id_fk",+ "tableFrom": "importSessions",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "importSessions_rootListId_bookmarkLists_id_fk": {+ "name": "importSessions_rootListId_bookmarkLists_id_fk",+ "tableFrom": "importSessions",+ "tableTo": "bookmarkLists",+ "columnsFrom": [+ "rootListId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "importStagingBookmarks": {+ "name": "importStagingBookmarks",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "importSessionId": {+ "name": "importSessionId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "type": {+ "name": "type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "url": {+ "name": "url",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "content": {+ "name": "content",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "note": {+ "name": "note",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "tags": {+ "name": "tags",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "listIds": {+ "name": "listIds",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "sourceAddedAt": {+ "name": "sourceAddedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'pending'"+ },+ "processingStartedAt": {+ "name": "processingStartedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "result": {+ "name": "result",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "resultReason": {+ "name": "resultReason",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "resultBookmarkId": {+ "name": "resultBookmarkId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "completedAt": {+ "name": "completedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "importStaging_session_status_idx": {+ "name": "importStaging_session_status_idx",+ "columns": [+ "importSessionId",+ "status"+ ],+ "isUnique": false+ },+ "importStaging_completedAt_idx": {+ "name": "importStaging_completedAt_idx",+ "columns": [+ "completedAt"+ ],+ "isUnique": false+ },+ "importStaging_status_idx": {+ "name": "importStaging_status_idx",+ "columns": [+ "status"+ ],+ "isUnique": false+ },+ "importStaging_status_processingStartedAt_idx": {+ "name": "importStaging_status_processingStartedAt_idx",+ "columns": [+ "status",+ "processingStartedAt"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "importStagingBookmarks_importSessionId_importSessions_id_fk": {+ "name": "importStagingBookmarks_importSessionId_importSessions_id_fk",+ "tableFrom": "importStagingBookmarks",+ "tableTo": "importSessions",+ "columnsFrom": [+ "importSessionId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "importStagingBookmarks_resultBookmarkId_bookmarks_id_fk": {+ "name": "importStagingBookmarks_resultBookmarkId_bookmarks_id_fk",+ "tableFrom": "importStagingBookmarks",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "resultBookmarkId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "invites": {+ "name": "invites",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "usedAt": {+ "name": "usedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "invitedBy": {+ "name": "invitedBy",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "invites_token_unique": {+ "name": "invites_token_unique",+ "columns": [+ "token"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "invites_invitedBy_user_id_fk": {+ "name": "invites_invitedBy_user_id_fk",+ "tableFrom": "invites",+ "tableTo": "user",+ "columnsFrom": [+ "invitedBy"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "listCollaborators": {+ "name": "listCollaborators",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "listId": {+ "name": "listId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "addedBy": {+ "name": "addedBy",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "listCollaborators_listId_idx": {+ "name": "listCollaborators_listId_idx",+ "columns": [+ "listId"+ ],+ "isUnique": false+ },+ "listCollaborators_userId_idx": {+ "name": "listCollaborators_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "listCollaborators_listId_userId_unique": {+ "name": "listCollaborators_listId_userId_unique",+ "columns": [+ "listId",+ "userId"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "listCollaborators_listId_bookmarkLists_id_fk": {+ "name": "listCollaborators_listId_bookmarkLists_id_fk",+ "tableFrom": "listCollaborators",+ "tableTo": "bookmarkLists",+ "columnsFrom": [+ "listId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "listCollaborators_userId_user_id_fk": {+ "name": "listCollaborators_userId_user_id_fk",+ "tableFrom": "listCollaborators",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "listCollaborators_addedBy_user_id_fk": {+ "name": "listCollaborators_addedBy_user_id_fk",+ "tableFrom": "listCollaborators",+ "tableTo": "user",+ "columnsFrom": [+ "addedBy"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "listInvitations": {+ "name": "listInvitations",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "listId": {+ "name": "listId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'pending'"+ },+ "invitedAt": {+ "name": "invitedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "invitedEmail": {+ "name": "invitedEmail",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "invitedBy": {+ "name": "invitedBy",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "listInvitations_listId_idx": {+ "name": "listInvitations_listId_idx",+ "columns": [+ "listId"+ ],+ "isUnique": false+ },+ "listInvitations_userId_idx": {+ "name": "listInvitations_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "listInvitations_status_idx": {+ "name": "listInvitations_status_idx",+ "columns": [+ "status"+ ],+ "isUnique": false+ },+ "listInvitations_listId_userId_unique": {+ "name": "listInvitations_listId_userId_unique",+ "columns": [+ "listId",+ "userId"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "listInvitations_listId_bookmarkLists_id_fk": {+ "name": "listInvitations_listId_bookmarkLists_id_fk",+ "tableFrom": "listInvitations",+ "tableTo": "bookmarkLists",+ "columnsFrom": [+ "listId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "listInvitations_userId_user_id_fk": {+ "name": "listInvitations_userId_user_id_fk",+ "tableFrom": "listInvitations",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "listInvitations_invitedBy_user_id_fk": {+ "name": "listInvitations_invitedBy_user_id_fk",+ "tableFrom": "listInvitations",+ "tableTo": "user",+ "columnsFrom": [+ "invitedBy"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "passwordResetToken": {+ "name": "passwordResetToken",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "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+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "passwordResetToken_token_unique": {+ "name": "passwordResetToken_token_unique",+ "columns": [+ "token"+ ],+ "isUnique": true+ },+ "passwordResetTokens_userId_idx": {+ "name": "passwordResetTokens_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "passwordResetToken_userId_user_id_fk": {+ "name": "passwordResetToken_userId_user_id_fk",+ "tableFrom": "passwordResetToken",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "rssFeedImports": {+ "name": "rssFeedImports",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "entryId": {+ "name": "entryId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "rssFeedId": {+ "name": "rssFeedId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "bookmarkId": {+ "name": "bookmarkId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "rssFeedImports_feedIdIdx_idx": {+ "name": "rssFeedImports_feedIdIdx_idx",+ "columns": [+ "rssFeedId"+ ],+ "isUnique": false+ },+ "rssFeedImports_entryIdIdx_idx": {+ "name": "rssFeedImports_entryIdIdx_idx",+ "columns": [+ "entryId"+ ],+ "isUnique": false+ },+ "rssFeedImports_rssFeedId_bookmarkId_idx": {+ "name": "rssFeedImports_rssFeedId_bookmarkId_idx",+ "columns": [+ "rssFeedId",+ "bookmarkId"+ ],+ "isUnique": false+ },+ "rssFeedImports_rssFeedId_entryId_unique": {+ "name": "rssFeedImports_rssFeedId_entryId_unique",+ "columns": [+ "rssFeedId",+ "entryId"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "rssFeedImports_rssFeedId_rssFeeds_id_fk": {+ "name": "rssFeedImports_rssFeedId_rssFeeds_id_fk",+ "tableFrom": "rssFeedImports",+ "tableTo": "rssFeeds",+ "columnsFrom": [+ "rssFeedId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "rssFeedImports_bookmarkId_bookmarks_id_fk": {+ "name": "rssFeedImports_bookmarkId_bookmarks_id_fk",+ "tableFrom": "rssFeedImports",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "bookmarkId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "set null",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "rssFeeds": {+ "name": "rssFeeds",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "url": {+ "name": "url",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "enabled": {+ "name": "enabled",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": true+ },+ "importTags": {+ "name": "importTags",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "lastFetchedAt": {+ "name": "lastFetchedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "lastFetchedStatus": {+ "name": "lastFetchedStatus",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'pending'"+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "rssFeeds_userId_idx": {+ "name": "rssFeeds_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "rssFeeds_userId_user_id_fk": {+ "name": "rssFeeds_userId_user_id_fk",+ "tableFrom": "rssFeeds",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "ruleEngineActions": {+ "name": "ruleEngineActions",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "ruleId": {+ "name": "ruleId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "action": {+ "name": "action",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "listId": {+ "name": "listId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "tagId": {+ "name": "tagId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "ruleEngineActions_userId_idx": {+ "name": "ruleEngineActions_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "ruleEngineActions_ruleId_idx": {+ "name": "ruleEngineActions_ruleId_idx",+ "columns": [+ "ruleId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "ruleEngineActions_userId_user_id_fk": {+ "name": "ruleEngineActions_userId_user_id_fk",+ "tableFrom": "ruleEngineActions",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "ruleEngineActions_ruleId_ruleEngineRules_id_fk": {+ "name": "ruleEngineActions_ruleId_ruleEngineRules_id_fk",+ "tableFrom": "ruleEngineActions",+ "tableTo": "ruleEngineRules",+ "columnsFrom": [+ "ruleId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "ruleEngineActions_userId_tagId_fk": {+ "name": "ruleEngineActions_userId_tagId_fk",+ "tableFrom": "ruleEngineActions",+ "tableTo": "bookmarkTags",+ "columnsFrom": [+ "userId",+ "tagId"+ ],+ "columnsTo": [+ "userId",+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "ruleEngineActions_userId_listId_fk": {+ "name": "ruleEngineActions_userId_listId_fk",+ "tableFrom": "ruleEngineActions",+ "tableTo": "bookmarkLists",+ "columnsFrom": [+ "userId",+ "listId"+ ],+ "columnsTo": [+ "userId",+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "ruleEngineRules": {+ "name": "ruleEngineRules",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "enabled": {+ "name": "enabled",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": true+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "event": {+ "name": "event",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "condition": {+ "name": "condition",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "listId": {+ "name": "listId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "tagId": {+ "name": "tagId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "ruleEngine_userId_idx": {+ "name": "ruleEngine_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "ruleEngineRules_userId_user_id_fk": {+ "name": "ruleEngineRules_userId_user_id_fk",+ "tableFrom": "ruleEngineRules",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "ruleEngineRules_userId_tagId_fk": {+ "name": "ruleEngineRules_userId_tagId_fk",+ "tableFrom": "ruleEngineRules",+ "tableTo": "bookmarkTags",+ "columnsFrom": [+ "userId",+ "tagId"+ ],+ "columnsTo": [+ "userId",+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "ruleEngineRules_userId_listId_fk": {+ "name": "ruleEngineRules_userId_listId_fk",+ "tableFrom": "ruleEngineRules",+ "tableTo": "bookmarkLists",+ "columnsFrom": [+ "userId",+ "listId"+ ],+ "columnsTo": [+ "userId",+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "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": {},+ "checkConstraints": {}+ },+ "subscriptions": {+ "name": "subscriptions",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "stripeCustomerId": {+ "name": "stripeCustomerId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "stripeSubscriptionId": {+ "name": "stripeSubscriptionId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "tier": {+ "name": "tier",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'free'"+ },+ "priceId": {+ "name": "priceId",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "cancelAtPeriodEnd": {+ "name": "cancelAtPeriodEnd",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": false+ },+ "startDate": {+ "name": "startDate",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "endDate": {+ "name": "endDate",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "modifiedAt": {+ "name": "modifiedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "subscriptions_userId_unique": {+ "name": "subscriptions_userId_unique",+ "columns": [+ "userId"+ ],+ "isUnique": true+ },+ "subscriptions_userId_idx": {+ "name": "subscriptions_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "subscriptions_stripeCustomerId_idx": {+ "name": "subscriptions_stripeCustomerId_idx",+ "columns": [+ "stripeCustomerId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "subscriptions_userId_user_id_fk": {+ "name": "subscriptions_userId_user_id_fk",+ "tableFrom": "subscriptions",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "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": [+ "tagId"+ ],+ "isUnique": false+ },+ "tagsOnBookmarks_bookmarkId_idx": {+ "name": "tagsOnBookmarks_bookmarkId_idx",+ "columns": [+ "bookmarkId"+ ],+ "isUnique": false+ },+ "tagsOnBookmarks_tagId_bookmarkId_idx": {+ "name": "tagsOnBookmarks_tagId_bookmarkId_idx",+ "columns": [+ "tagId",+ "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": {},+ "checkConstraints": {}+ },+ "userReadingProgress": {+ "name": "userReadingProgress",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "bookmarkId": {+ "name": "bookmarkId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "readingProgressOffset": {+ "name": "readingProgressOffset",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "readingProgressAnchor": {+ "name": "readingProgressAnchor",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "readingProgressPercent": {+ "name": "readingProgressPercent",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "modifiedAt": {+ "name": "modifiedAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "userReadingProgress_bookmarkId_idx": {+ "name": "userReadingProgress_bookmarkId_idx",+ "columns": [+ "bookmarkId"+ ],+ "isUnique": false+ },+ "userReadingProgress_userId_idx": {+ "name": "userReadingProgress_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "userReadingProgress_bookmarkId_userId_unique": {+ "name": "userReadingProgress_bookmarkId_userId_unique",+ "columns": [+ "bookmarkId",+ "userId"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "userReadingProgress_bookmarkId_bookmarks_id_fk": {+ "name": "userReadingProgress_bookmarkId_bookmarks_id_fk",+ "tableFrom": "userReadingProgress",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "bookmarkId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "userReadingProgress_userId_user_id_fk": {+ "name": "userReadingProgress_userId_user_id_fk",+ "tableFrom": "userReadingProgress",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "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+ },+ "salt": {+ "name": "salt",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'user'"+ },+ "bookmarkQuota": {+ "name": "bookmarkQuota",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "storageQuota": {+ "name": "storageQuota",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "browserCrawlingEnabled": {+ "name": "browserCrawlingEnabled",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "bookmarkClickAction": {+ "name": "bookmarkClickAction",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'open_original_link'"+ },+ "archiveDisplayBehaviour": {+ "name": "archiveDisplayBehaviour",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'show'"+ },+ "timezone": {+ "name": "timezone",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'UTC'"+ },+ "backupsEnabled": {+ "name": "backupsEnabled",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": false+ },+ "backupsFrequency": {+ "name": "backupsFrequency",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'weekly'"+ },+ "backupsRetentionDays": {+ "name": "backupsRetentionDays",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": 30+ },+ "readerFontSize": {+ "name": "readerFontSize",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "readerLineHeight": {+ "name": "readerLineHeight",+ "type": "real",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "readerFontFamily": {+ "name": "readerFontFamily",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "autoTaggingEnabled": {+ "name": "autoTaggingEnabled",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "autoSummarizationEnabled": {+ "name": "autoSummarizationEnabled",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "tagStyle": {+ "name": "tagStyle",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'titlecase-spaces'"+ },+ "curatedTagIds": {+ "name": "curatedTagIds",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "inferredTagLang": {+ "name": "inferredTagLang",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "user_email_unique": {+ "name": "user_email_unique",+ "columns": [+ "email"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ },+ "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": {},+ "checkConstraints": {}+ },+ "webhooks": {+ "name": "webhooks",+ "columns": {+ "id": {+ "name": "id",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "url": {+ "name": "url",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "events": {+ "name": "events",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {+ "webhooks_userId_idx": {+ "name": "webhooks_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "webhooks_userId_user_id_fk": {+ "name": "webhooks_userId_user_id_fk",+ "tableFrom": "webhooks",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "checkConstraints": {}+ }+ },+ "views": {},+ "enums": {},+ "_meta": {+ "schemas": {},+ "tables": {},+ "columns": {}+ },+ "internal": {+ "indexes": {}+ }+}\ No newline at end of filediff --git a/packages/db/drizzle/meta/_journal.json b/packages/db/drizzle/meta/_journal.jsonindex 34e6656b..3df04b54 100644--- a/packages/db/drizzle/meta/_journal.json+++ b/packages/db/drizzle/meta/_journal.json@@ -561,6 +561,13 @@"when": 1770564384451,"tag": "0079_add_tag_granularity_settings","breakpoints": true+ },+ {+ "idx": 80,+ "version": "6",+ "when": 1771481519588,+ "tag": "0080_user_reading_progress",+ "breakpoints": true}]}\ No newline at end of filediff --git a/packages/db/schema.ts b/packages/db/schema.tsindex 2b237e25..02a3a077 100644--- a/packages/db/schema.ts+++ b/packages/db/schema.ts@@ -358,6 +358,33 @@ export const highlights = sqliteTable(],);+export const userReadingProgress = sqliteTable(+ "userReadingProgress",+ {+ id: text("id")+ .notNull()+ .primaryKey()+ .$defaultFn(() => createId()),+ bookmarkId: text("bookmarkId")+ .notNull()+ .references(() => bookmarks.id, {+ onDelete: "cascade",+ }),+ userId: text("userId")+ .notNull()+ .references(() => users.id, { onDelete: "cascade" }),+ readingProgressOffset: integer("readingProgressOffset").notNull(),+ readingProgressAnchor: text("readingProgressAnchor"),+ readingProgressPercent: integer("readingProgressPercent"),+ modifiedAt: modifiedAtField(),+ },+ (tb) => [+ unique().on(tb.bookmarkId, tb.userId),+ index("userReadingProgress_bookmarkId_idx").on(tb.bookmarkId),+ index("userReadingProgress_userId_idx").on(tb.userId),+ ],+);+export const bookmarkTexts = sqliteTable("bookmarkTexts", {id: text("id").notNull()@@ -1174,3 +1201,17 @@ export const backupsRelations = relations(backupsTable, ({ one }) => ({references: [assets.id],}),}));++export const userReadingProgressRelations = relations(+ userReadingProgress,+ ({ one }) => ({+ bookmark: one(bookmarks, {+ fields: [userReadingProgress.bookmarkId],+ references: [bookmarks.id],+ }),+ user: one(users, {+ fields: [userReadingProgress.userId],+ references: [users.id],+ }),+ }),+);diff --git a/packages/shared-react/components/BookmarkHtmlHighlighter.tsx b/packages/shared-react/components/BookmarkHtmlHighlighter.tsxindex 971c6cdf..0c8298ff 100644--- a/packages/shared-react/components/BookmarkHtmlHighlighter.tsx+++ b/packages/shared-react/components/BookmarkHtmlHighlighter.tsx@@ -1,4 +1,10 @@-import React, { useEffect, useRef, useState } from "react";+import React, {+ forwardRef,+ useEffect,+ useImperativeHandle,+ useRef,+ useState,+} from "react";import { cn } from "@/lib/utils";import { PopoverAnchor } from "@radix-ui/react-popover";import { Check, Trash2 } from "lucide-react";@@ -140,17 +146,27 @@ interface HTMLHighlighterProps {onDeleteHighlight?: (highlight: Highlight) => void;}-function BookmarkHTMLHighlighter({- htmlContent,- className,- style,- highlights = [],- readOnly = false,- onHighlight,- onUpdateHighlight,- onDeleteHighlight,-}: HTMLHighlighterProps) {+const BookmarkHTMLHighlighter = forwardRef<+ HTMLDivElement,+ HTMLHighlighterProps+>(function BookmarkHTMLHighlighter(+ {+ htmlContent,+ className,+ style,+ highlights = [],+ readOnly = false,+ onHighlight,+ onUpdateHighlight,+ onDeleteHighlight,+ },+ ref,+) {const contentRef = useRef<HTMLDivElement>(null);++ // Expose the content div ref to parent components+ useImperativeHandle(ref, () => contentRef.current!, []);+const [menuPosition, setMenuPosition] = useState<{x: number;y: number;@@ -409,6 +425,6 @@ function BookmarkHTMLHighlighter({/></div>);-}+});export default BookmarkHTMLHighlighter;diff --git a/packages/shared-react/components/ScrollProgressTracker.tsx b/packages/shared-react/components/ScrollProgressTracker.tsxnew file mode 100644index 00000000..dab6d8c8--- /dev/null+++ b/packages/shared-react/components/ScrollProgressTracker.tsx@@ -0,0 +1,229 @@+import React, {+ forwardRef,+ useEffect,+ useImperativeHandle,+ useRef,+ useState,+} from "react";++import type { ReadingPosition } from "@karakeep/shared/utils/reading-progress-dom";+import {+ findScrollableParent,+ getReadingPosition,+ SCROLL_THROTTLE_MS,+ scrollToReadingPosition,+} from "@karakeep/shared/utils/reading-progress-dom";++/** Delay after the last scroll event before reporting position (milliseconds) */+const IDLE_SAVE_DELAY_MS = 5000;++/** Delay after the last scroll event before hiding the progress bar (milliseconds) */+const PROGRESS_BAR_HIDE_DELAY_MS = 2000;++interface ScrollProgressTrackerProps {+ /** Called lazily on intent signals (idle, visibility change, beforeunload, unmount) — use for persisting position */+ onSavePosition?: (position: ReadingPosition) => void;+ /** Called on every throttled scroll — use for responsive UI (banner dismissal, etc.) */+ onScrollPositionChange?: (position: ReadingPosition) => void;+ /** When set to true, scrolls to the saved reading position */+ restorePosition?: boolean;+ readingProgressOffset?: number | null;+ readingProgressAnchor?: string | null;+ /** Show a Medium-style reading progress bar at the top */+ showProgressBar?: boolean;+ /** Custom styles for the progress bar container (e.g. positioning overrides) */+ progressBarStyle?: React.CSSProperties;+ children: React.ReactNode;+}++/**+ * Wraps content and tracks scroll progress, reporting position changes+ * lazily (idle after scrolling, visibility change, beforeunload, unmount).+ * Can also restore a previously saved reading position.+ */+const ScrollProgressTracker = forwardRef<+ HTMLDivElement,+ ScrollProgressTrackerProps+>(function ScrollProgressTracker(+ {+ onSavePosition,+ onScrollPositionChange,+ restorePosition,+ readingProgressOffset,+ readingProgressAnchor,+ showProgressBar,+ progressBarStyle,+ children,+ },+ ref,+) {+ const containerRef = useRef<HTMLDivElement>(null);+ useImperativeHandle(ref, () => containerRef.current!, []);+ const [scrollPercent, setScrollPercent] = useState(0);+ const [progressBarVisible, setProgressBarVisible] = useState(false);+ const latestPositionRef = useRef<ReadingPosition | null>(null);++ const onSavePositionRef = useRef(onSavePosition);+ const onScrollPositionChangeRef = useRef(onScrollPositionChange);+ useEffect(() => {+ onSavePositionRef.current = onSavePosition;+ onScrollPositionChangeRef.current = onScrollPositionChange;+ });++ // Restore reading position when triggered+ const hasRestoredRef = useRef(false);+ useEffect(() => {+ if (+ !restorePosition ||+ hasRestoredRef.current ||+ !readingProgressOffset ||+ readingProgressOffset <= 0+ )+ return;++ hasRestoredRef.current = true;+ const rafId = requestAnimationFrame(() => {+ const container = containerRef.current;+ if (!container) return;++ scrollToReadingPosition(+ container,+ readingProgressOffset,+ "smooth",+ readingProgressAnchor,+ );+ });++ return () => cancelAnimationFrame(rafId);+ }, [restorePosition, readingProgressOffset, readingProgressAnchor]);++ // Scroll tracking — updates the progress bar on every scroll,+ // but only reports position lazily via an idle timer.+ useEffect(() => {+ const container = containerRef.current;+ if (!container) return;++ let lastScrollTime = 0;+ let idleTimerId: ReturnType<typeof setTimeout> | null = null;+ let hideBarTimerId: ReturnType<typeof setTimeout> | null = null;+ let trailingTimerId: ReturnType<typeof setTimeout> | null = null;++ const reportLatestPosition = () => {+ const pos = latestPositionRef.current;+ if (pos && pos.offset > 0 && onSavePositionRef.current) {+ onSavePositionRef.current(pos);+ }+ };++ const processScroll = () => {+ lastScrollTime = Date.now();++ const position = getReadingPosition(container);+ if (position) {+ setScrollPercent(position.percent);+ latestPositionRef.current = position;+ if (onScrollPositionChangeRef.current) {+ onScrollPositionChangeRef.current(position);+ }+ }++ // Show progress bar on scroll, hide after idle+ setProgressBarVisible(true);+ if (hideBarTimerId) clearTimeout(hideBarTimerId);+ hideBarTimerId = setTimeout(+ () => setProgressBarVisible(false),+ PROGRESS_BAR_HIDE_DELAY_MS,+ );++ // Reset idle timer — report position after scrolling stops+ if (idleTimerId) clearTimeout(idleTimerId);+ idleTimerId = setTimeout(reportLatestPosition, IDLE_SAVE_DELAY_MS);+ };++ const handleScroll = () => {+ const now = Date.now();+ if (now - lastScrollTime < SCROLL_THROTTLE_MS) {+ // Schedule a trailing call so the last scroll event is never lost+ if (!trailingTimerId) {+ trailingTimerId = setTimeout(() => {+ trailingTimerId = null;+ processScroll();+ }, SCROLL_THROTTLE_MS);+ }+ return;+ }+ processScroll();+ };++ const scrollParent = findScrollableParent(container);+ const isWindowScroll = scrollParent === document.documentElement;+ const target: HTMLElement | Window = isWindowScroll ? window : scrollParent;++ target.addEventListener("scroll", handleScroll, { passive: true });++ return () => {+ target.removeEventListener("scroll", handleScroll);+ if (idleTimerId) clearTimeout(idleTimerId);+ if (hideBarTimerId) clearTimeout(hideBarTimerId);+ if (trailingTimerId) clearTimeout(trailingTimerId);+ };+ }, []);++ // Report position on visibility change, beforeunload, and unmount+ useEffect(() => {+ const reportPosition = () => {+ const pos = latestPositionRef.current;+ if (pos && pos.offset > 0 && onSavePositionRef.current) {+ onSavePositionRef.current(pos);+ }+ };++ const handleVisibilityChange = () => {+ if (document.visibilityState === "hidden") {+ reportPosition();+ }+ };++ document.addEventListener("visibilitychange", handleVisibilityChange);+ window.addEventListener("beforeunload", reportPosition);++ return () => {+ reportPosition();+ document.removeEventListener("visibilitychange", handleVisibilityChange);+ window.removeEventListener("beforeunload", reportPosition);+ };+ }, []);++ return (+ <div ref={containerRef}>+ {showProgressBar && (+ <div+ style={{+ position: "sticky",+ top: 0,+ left: 0,+ right: 0,+ height: 3,+ zIndex: 50,+ backgroundColor: "transparent",+ opacity: progressBarVisible ? 1 : 0,+ transition: "opacity 300ms ease-out",+ ...progressBarStyle,+ }}+ >+ <div+ style={{+ height: "100%",+ width: `${scrollPercent}%`,+ backgroundColor: "rgb(249, 115, 22)",+ transition: "width 150ms ease-out",+ }}+ />+ </div>+ )}+ {children}+ </div>+ );+});++export default ScrollProgressTracker;diff --git a/packages/shared-react/hooks/reading-progress.ts b/packages/shared-react/hooks/reading-progress.tsnew file mode 100644index 00000000..2302ab92--- /dev/null+++ b/packages/shared-react/hooks/reading-progress.ts@@ -0,0 +1,146 @@+import { useCallback, useEffect, useRef, useState } from "react";+import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";++import type { ReadingPosition } from "@karakeep/shared/utils/reading-progress-dom";++import { useTRPC } from "../trpc";++interface UseReadingProgressOptions {+ bookmarkId: string;+}++/**+ * Unified reading progress hook for web and mobile.+ *+ * Handles:+ * - Fetching reading progress via its own tRPC query+ * - Capturing initial reading position (stable across query re-fetches)+ * - "Continue reading" banner state and auto-dismiss on scroll past 15%+ * - Lazy saving via onSavePosition (idle, visibility change, unmount)+ * - Deduplication of save calls by offset+ *+ * Pass the returned `onSavePosition` and `onScrollPositionChange` to ScrollProgressTracker.+ */+export function useReadingProgress({ bookmarkId }: UseReadingProgressOptions) {+ const api = useTRPC();+ const queryClient = useQueryClient();++ const { data: progressData } = useQuery(+ api.bookmarks.getReadingProgress.queryOptions({ bookmarkId }),+ );++ const readingProgressOffset = progressData?.readingProgressOffset;+ const readingProgressAnchor = progressData?.readingProgressAnchor;+ const readingProgressPercent = progressData?.readingProgressPercent;++ // Capture initial reading progress on first load — stays stable across re-fetches+ const initialProgressRef = useRef<{+ offset: number | null;+ anchor: string | null;+ percent: number | null;+ } | null>(null);+ const previousBookmarkIdRef = useRef<string | null>(null);+ const lastSavedOffset = useRef<number | null>(null);++ if (previousBookmarkIdRef.current !== bookmarkId) {+ previousBookmarkIdRef.current = bookmarkId;+ initialProgressRef.current = null;+ lastSavedOffset.current = null;+ }++ // Only capture once data has loaded (offset transitions from undefined to a value)+ if (!initialProgressRef.current && readingProgressOffset !== undefined) {+ initialProgressRef.current = {+ offset: readingProgressOffset ?? null,+ anchor: readingProgressAnchor ?? null,+ percent: readingProgressPercent ?? null,+ };+ }++ if (+ lastSavedOffset.current === null &&+ initialProgressRef.current?.offset != null+ ) {+ lastSavedOffset.current = initialProgressRef.current.offset;+ }++ const initialOffset = initialProgressRef.current?.offset ?? null;+ const initialAnchor = initialProgressRef.current?.anchor ?? null;+ const initialPercent = initialProgressRef.current?.percent ?? null;++ // Banner state+ const [bannerDismissed, setBannerDismissed] = useState(false);+ const [restoreRequested, setRestoreRequested] = useState(false);+ const showBanner =+ !!initialOffset &&+ initialOffset > 0 &&+ initialPercent != null &&+ initialPercent >= 10 &&+ initialPercent < 100 &&+ !bannerDismissed;++ const bannerVisibleRef = useRef(false);+ bannerVisibleRef.current = showBanner;++ useEffect(() => {+ setBannerDismissed(false);+ setRestoreRequested(false);+ }, [bookmarkId]);++ // Save mutation+ const { mutate: updateProgress } = useMutation(+ api.bookmarks.updateReadingProgress.mutationOptions({+ onSuccess: () => {+ queryClient.invalidateQueries(+ api.bookmarks.getReadingProgress.pathFilter(),+ );+ },+ }),+ );++ // Lazy save — called by ScrollProgressTracker on idle/visibility/beforeunload/unmount+ const onSavePosition = useCallback(+ (position: ReadingPosition) => {+ if (bannerVisibleRef.current) return;+ if (lastSavedOffset.current === position.offset) return;+ lastSavedOffset.current = position.offset;+ updateProgress({+ bookmarkId,+ readingProgressOffset: position.offset,+ readingProgressAnchor: position.anchor,+ readingProgressPercent: position.percent,+ });+ },+ [bookmarkId, updateProgress],+ );++ // Responsive — called on every throttled scroll for banner dismissal+ const onScrollPositionChange = useCallback((position: ReadingPosition) => {+ if (bannerVisibleRef.current && position.percent > 15) {+ setBannerDismissed(true);+ }+ }, []);++ const onContinue = useCallback(() => {+ setRestoreRequested(true);+ setBannerDismissed(true);+ }, []);++ const onDismiss = useCallback(() => {+ setBannerDismissed(true);+ }, []);++ return {+ // Banner+ showBanner,+ bannerPercent: initialPercent,+ onContinue,+ onDismiss,+ // ScrollProgressTracker props+ restorePosition: restoreRequested,+ readingProgressOffset: initialOffset,+ readingProgressAnchor: initialAnchor,+ onSavePosition,+ onScrollPositionChange,+ };+}diff --git a/packages/shared/utils/reading-progress-dom.test.ts b/packages/shared/utils/reading-progress-dom.test.tsnew file mode 100644index 00000000..831e9998--- /dev/null+++ b/packages/shared/utils/reading-progress-dom.test.ts@@ -0,0 +1,56 @@+import { describe, expect, test } from "vitest";++import { normalizeText, normalizeTextLength } from "./reading-progress-dom";++describe("normalizeText", () => {+ test("collapses multiple spaces to single space", () => {+ expect(normalizeText("hello world")).toBe("hello world");+ });++ test("collapses newlines and tabs to single space", () => {+ expect(normalizeText("hello\n\nworld")).toBe("hello world");+ expect(normalizeText("hello\t\tworld")).toBe("hello world");+ expect(normalizeText("hello\r\nworld")).toBe("hello world");+ });++ test("trims leading and trailing whitespace", () => {+ expect(normalizeText(" hello world ")).toBe("hello world");+ expect(normalizeText("\n\nhello world\n\n")).toBe("hello world");+ });++ test("handles empty string", () => {+ expect(normalizeText("")).toBe("");+ });++ test("handles whitespace-only string", () => {+ expect(normalizeText(" ")).toBe("");+ expect(normalizeText("\n\t\r")).toBe("");+ });++ test("handles text with no extra whitespace", () => {+ expect(normalizeText("hello world")).toBe("hello world");+ });++ test("handles mixed whitespace types", () => {+ expect(normalizeText("hello \n\t world")).toBe("hello world");+ });+});++describe("normalizeTextLength", () => {+ test("returns length of normalized text", () => {+ expect(normalizeTextLength("hello world")).toBe(11);+ });++ test("returns normalized length for text with extra whitespace", () => {+ // "hello world" normalizes to "hello world" (11 chars)+ expect(normalizeTextLength("hello world")).toBe(11);+ });++ test("returns 0 for empty string", () => {+ expect(normalizeTextLength("")).toBe(0);+ });++ test("returns 0 for whitespace-only string", () => {+ expect(normalizeTextLength(" \n\t")).toBe(0);+ });+});diff --git a/packages/shared/utils/reading-progress-dom.ts b/packages/shared/utils/reading-progress-dom.tsnew file mode 100644index 00000000..4c97e910--- /dev/null+++ b/packages/shared/utils/reading-progress-dom.ts@@ -0,0 +1,334 @@+/**+ * Reading Progress Utilities+ *+ * Functions for reading position tracking in web contexts.+ * Includes text normalization, position calculation, scroll restoration,+ * and Radix ScrollArea detection.+ */++/**+ * Reading position data including offset, anchor text for verification, and percentage.+ */+export interface ReadingPosition {+ offset: number;+ anchor: string;+ percent: number;+}++const PARAGRAPH_SELECTORS = [+ "p",+ "h1",+ "h2",+ "h3",+ "h4",+ "h5",+ "h6",+ "li",+ "blockquote",+];++const PARAGRAPH_SELECTOR_STRING = PARAGRAPH_SELECTORS.join(", ");++/**+ * Maximum length of anchor text extracted from paragraphs.+ * Used for position verification when restoring reading progress.+ */+export const ANCHOR_TEXT_MAX_LENGTH = 50;++/** Threshold in pixels for detecting "scrolled to bottom" */+const SCROLL_BOTTOM_THRESHOLD = 5;++/** Minimum interval between scroll position updates (milliseconds) */+export const SCROLL_THROTTLE_MS = 150;++/**+ * Scroll position info for determining if user is at bottom of content.+ */+interface ScrollInfo {+ scrollTop: number;+ scrollHeight: number;+ clientHeight: number;+}++/**+ * Normalizes text by collapsing all whitespace to single spaces and trimming.+ * This ensures consistent character counting regardless of HTML formatting.+ */+export function normalizeText(text: string): string {+ return text+ .replace(/[\n\r\t]+/g, " ")+ .replace(/\s+/g, " ")+ .trim();+}++/**+ * Returns the normalized length of text for consistent offset calculation.+ */+export function normalizeTextLength(text: string): number {+ return normalizeText(text).length;+}++/**+ * Check if element is visible (not hidden by CSS display:none).+ * Uses bounding rect - hidden elements have 0 dimensions.+ * We use this instead of offsetParent because dialogs use position:fixed,+ * which makes offsetParent null even for visible elements.+ */+export function isElementVisible(element: HTMLElement | null): boolean {+ if (!element) return false;+ const rect = element.getBoundingClientRect();+ return rect.width > 0 && rect.height > 0;+}++/**+ * Finds the nearest scrollable ancestor of an element.+ * Handles both standard overflow-based scrolling, Radix ScrollArea components,+ * and window-level scrolling (falls back to document.documentElement).+ */+export function findScrollableParent(element: HTMLElement): HTMLElement {+ let current: HTMLElement | null = element.parentElement;++ while (current) {+ const style = getComputedStyle(current);+ const overflowY = style.overflowY;+ const isOverflowScrollable = overflowY === "auto" || overflowY === "scroll";+ // Check for Radix ScrollArea viewport (uses data attribute for scrolling)+ const isRadixViewport = current.hasAttribute(+ "data-radix-scroll-area-viewport",+ );++ const isCandidate = isOverflowScrollable || isRadixViewport;+ const hasScrollContent = current.scrollHeight > current.clientHeight;++ if (isCandidate && hasScrollContent) {+ return current;+ }+ current = current.parentElement;+ }++ // Fall back to document.documentElement for window-level scrolling+ return document.documentElement;+}++/**+ * Calculates the text offset of the paragraph at the top of the viewport.+ * Finds the paragraph whose top edge is at or near the top of the visible area.+ * Returns offset, anchor text for position verification, and percentage through the document.+ *+ * Handles nested scrolling with Radix ScrollArea detection.+ * Returns 100% when scrolled to the bottom of the document.+ */+export function getReadingPosition(+ container: HTMLElement,+): ReadingPosition | null {+ // Find the scrollable parent to get the correct viewport reference+ const scrollParent = findScrollableParent(container);+ const isWindowScroll = scrollParent === document.documentElement;++ // Build scroll info for 100% detection+ const scrollInfo: ScrollInfo = {+ scrollTop: isWindowScroll ? window.scrollY : scrollParent.scrollTop,+ scrollHeight: isWindowScroll+ ? document.body.scrollHeight+ : scrollParent.scrollHeight,+ clientHeight: isWindowScroll+ ? window.innerHeight+ : scrollParent.clientHeight,+ };++ // For window-level scrolling, viewport top is 0; for container scrolling, use container's top+ const viewportTop = isWindowScroll+ ? 0+ : scrollParent.getBoundingClientRect().top;++ return getReadingPositionWithViewport(container, viewportTop, scrollInfo);+}++/**+ * Calculates the text offset of the paragraph at the top of the viewport.+ * Takes explicit viewport top position and optional scroll info for bottom detection.+ */+function getReadingPositionWithViewport(+ container: HTMLElement,+ viewportTop: number,+ scrollInfo?: ScrollInfo,+): ReadingPosition | null {+ const paragraphs = Array.from(+ container.querySelectorAll(PARAGRAPH_SELECTOR_STRING),+ );+ if (paragraphs.length === 0) return null;++ // Calculate total length for percentage calculation+ const totalLength = normalizeTextLength(container.textContent ?? "");++ // Check if scrolled to bottom - return 100% immediately+ if (scrollInfo) {+ const { scrollTop, scrollHeight, clientHeight } = scrollInfo;+ const isAtBottom =+ scrollTop + clientHeight >= scrollHeight - SCROLL_BOTTOM_THRESHOLD;++ if (isAtBottom) {+ // Find the last paragraph for anchor text+ const lastParagraph = paragraphs[paragraphs.length - 1];+ const anchor = lastParagraph+ ? normalizeText(lastParagraph.textContent ?? "").slice(+ 0,+ ANCHOR_TEXT_MAX_LENGTH,+ )+ : "";++ return { offset: totalLength, anchor, percent: 100 };+ }+ }++ // Find the paragraph at the top of the viewport+ let topParagraph: Element | null = null;++ for (const paragraph of paragraphs) {+ const rect = paragraph.getBoundingClientRect();++ // If this paragraph's top is at or below the viewport top, it's our target+ if (rect.top >= viewportTop) {+ topParagraph = paragraph;+ break;+ }++ // If this paragraph spans the viewport top (started above, ends below), use it+ if (rect.top < viewportTop && rect.bottom > viewportTop) {+ topParagraph = paragraph;+ break;+ }+ }++ if (!topParagraph) return null;++ // Extract anchor text for position verification+ const anchor = normalizeText(topParagraph.textContent ?? "").slice(+ 0,+ ANCHOR_TEXT_MAX_LENGTH,+ );++ // Calculate the text offset of this paragraph using TreeWalker+ const walker = document.createTreeWalker(+ container,+ NodeFilter.SHOW_TEXT,+ null,+ );++ let offset = 0;+ let node: Node | null;+ while ((node = walker.nextNode())) {+ if (topParagraph.contains(node)) {+ // Found the start of our target paragraph+ // Calculate percentage (clamped to 0-100)+ const percent =+ totalLength > 0+ ? Math.min(100, Math.max(0, Math.round((offset / totalLength) * 100)))+ : 0;+ return { offset, anchor, percent };+ }+ offset += normalizeTextLength(node.textContent ?? "");+ }++ // topParagraph has no text nodes (empty or contains only non-text elements)+ return null;+}++/**+ * Scrolls to the position in the content corresponding to the given text offset.+ * Uses anchor text for verification when available, falling back to offset-based lookup.+ */+export function scrollToReadingPosition(+ container: HTMLElement,+ offset: number,+ behavior: ScrollBehavior = "smooth",+ anchor?: string | null,+): boolean {+ if (offset <= 0) return false;++ // Strategy 1: Try to find paragraph by anchor text (most reliable)+ if (anchor) {+ const paragraphs = Array.from(+ container.querySelectorAll(PARAGRAPH_SELECTOR_STRING),+ );++ let fuzzyMatch: Element | null = null;+ const anchorPrefix = anchor.slice(0, 20);++ for (const paragraph of paragraphs) {+ const paragraphAnchor = normalizeText(paragraph.textContent ?? "").slice(+ 0,+ ANCHOR_TEXT_MAX_LENGTH,+ );++ // Exact match - immediate return+ if (paragraphAnchor === anchor) {+ paragraph.scrollIntoView({ behavior, block: "start" });+ return true;+ }++ // Track first fuzzy match for fallback (first 20 chars match)+ if (+ !fuzzyMatch &&+ anchor.length >= 20 &&+ paragraphAnchor.startsWith(anchorPrefix)+ ) {+ fuzzyMatch = paragraph;+ }+ }++ if (fuzzyMatch) {+ fuzzyMatch.scrollIntoView({ behavior, block: "start" });+ return true;+ }+ }++ // Strategy 2: Fall back to offset-based lookup+ const walker = document.createTreeWalker(+ container,+ NodeFilter.SHOW_TEXT,+ null,+ );++ let currentOffset = 0;+ let node: Node | null;+ while ((node = walker.nextNode())) {+ const textContent = node.textContent ?? "";+ // Use normalized length for consistent offset calculation+ const nodeLength = normalizeTextLength(textContent);++ // Skip nodes with no meaningful content (whitespace-only nodes normalize to length 0)+ if (nodeLength === 0) {+ continue;+ }++ // Check if we've passed the target offset+ if (currentOffset + nodeLength >= offset) {+ // Found the text node containing our offset+ // Find the enclosing paragraph element+ let targetElement: HTMLElement | null = node.parentElement;+ while (targetElement && targetElement !== container) {+ const tagName = targetElement.tagName.toLowerCase();+ if (PARAGRAPH_SELECTORS.includes(tagName)) {+ break;+ }+ targetElement = targetElement.parentElement;+ }++ // Use the text node's parent if no paragraph found+ if (!targetElement || targetElement === container) {+ targetElement = node.parentElement;+ }++ if (targetElement) {+ targetElement.scrollIntoView({ behavior, block: "start" });+ return true;+ }+ break;+ }++ currentOffset += nodeLength;+ }++ return false;+}diff --git a/packages/trpc/routers/bookmarks.test.ts b/packages/trpc/routers/bookmarks.test.tsindex 13df8a9e..3de51c6c 100644--- a/packages/trpc/routers/bookmarks.test.ts+++ b/packages/trpc/routers/bookmarks.test.ts@@ -1076,4 +1076,308 @@ describe("Bookmark Routes", () => {);});});++ describe("Reading Progress", () => {+ test<CustomTestContext>("saves and retrieves reading progress", async ({+ apiCallers,+ }) => {+ const api = apiCallers[0].bookmarks;++ // Create a link bookmark+ const bookmark = await api.createBookmark({+ url: "https://example.com/article",+ type: BookmarkTypes.LINK,+ });++ // Save reading progress+ await api.updateReadingProgress({+ bookmarkId: bookmark.id,+ readingProgressOffset: 1500,+ readingProgressAnchor: "This is the anchor text for verification",+ });++ // Retrieve and verify progress via getReadingProgress+ const progress = await api.getReadingProgress({+ bookmarkId: bookmark.id,+ });+ expect(progress.readingProgressOffset).toBe(1500);+ expect(progress.readingProgressAnchor).toBe(+ "This is the anchor text for verification",+ );+ });++ test<CustomTestContext>("updates existing progress (upsert behavior)", async ({+ apiCallers,+ }) => {+ const api = apiCallers[0].bookmarks;++ const bookmark = await api.createBookmark({+ url: "https://example.com/article",+ type: BookmarkTypes.LINK,+ });++ // Save initial progress+ await api.updateReadingProgress({+ bookmarkId: bookmark.id,+ readingProgressOffset: 500,+ readingProgressAnchor: "First anchor",+ });++ // Update progress+ await api.updateReadingProgress({+ bookmarkId: bookmark.id,+ readingProgressOffset: 2000,+ readingProgressAnchor: "Updated anchor",+ });++ // Verify updated values+ const progress = await api.getReadingProgress({+ bookmarkId: bookmark.id,+ });+ expect(progress.readingProgressOffset).toBe(2000);+ expect(progress.readingProgressAnchor).toBe("Updated anchor");+ });++ test<CustomTestContext>("two users have independent progress on same bookmark", async ({+ apiCallers,+ }) => {+ const api1 = apiCallers[0].bookmarks;+ const api2 = apiCallers[1].bookmarks;++ // User 1 creates a bookmark+ const bookmark = await api1.createBookmark({+ url: "https://example.com/shared-article",+ type: BookmarkTypes.LINK,+ });++ // User 1 saves progress at position 1000+ await api1.updateReadingProgress({+ bookmarkId: bookmark.id,+ readingProgressOffset: 1000,+ readingProgressAnchor: "User 1 anchor",+ });++ // User 2 creates the same bookmark (different bookmark ID, same URL)+ const bookmark2 = await api2.createBookmark({+ url: "https://example.com/shared-article",+ type: BookmarkTypes.LINK,+ });++ // User 2 saves progress at position 3000+ await api2.updateReadingProgress({+ bookmarkId: bookmark2.id,+ readingProgressOffset: 3000,+ readingProgressAnchor: "User 2 anchor",+ });++ // Verify each user sees their own progress+ const progress1 = await api1.getReadingProgress({+ bookmarkId: bookmark.id,+ });+ const progress2 = await api2.getReadingProgress({+ bookmarkId: bookmark2.id,+ });++ expect(progress1.readingProgressOffset).toBe(1000);+ expect(progress1.readingProgressAnchor).toBe("User 1 anchor");++ expect(progress2.readingProgressOffset).toBe(3000);+ expect(progress2.readingProgressAnchor).toBe("User 2 anchor");+ });++ test<CustomTestContext>("rejects reading progress on TEXT bookmark", async ({+ apiCallers,+ }) => {+ const api = apiCallers[0].bookmarks;++ const bookmark = await api.createBookmark({+ text: "Some text content",+ type: BookmarkTypes.TEXT,+ });++ await expect(() =>+ api.updateReadingProgress({+ bookmarkId: bookmark.id,+ readingProgressOffset: 100,+ }),+ ).rejects.toThrow(+ /Reading progress can only be saved for link bookmarks/,+ );+ });++ test<CustomTestContext>("reading progress is deleted when bookmark is deleted", async ({+ apiCallers,+ }) => {+ const api = apiCallers[0].bookmarks;++ const bookmark = await api.createBookmark({+ url: "https://example.com/to-delete",+ type: BookmarkTypes.LINK,+ });++ // Save reading progress+ await api.updateReadingProgress({+ bookmarkId: bookmark.id,+ readingProgressOffset: 500,+ readingProgressAnchor: "Will be deleted",+ });++ // Verify progress exists+ const progress = await api.getReadingProgress({+ bookmarkId: bookmark.id,+ });+ expect(progress.readingProgressOffset).toBe(500);++ // Delete the bookmark+ await api.deleteBookmark({ bookmarkId: bookmark.id });++ // Verify bookmark is gone (and implicitly, the progress cascade deleted)+ await expect(() =>+ api.getBookmark({ bookmarkId: bookmark.id }),+ ).rejects.toThrow(/Bookmark not found/);+ });++ test<CustomTestContext>("collaborator can save reading progress on shared bookmark", async ({+ apiCallers,+ }) => {+ const ownerApi = apiCallers[0];+ const collaboratorApi = apiCallers[1];++ // Owner creates a link bookmark+ const bookmark = await ownerApi.bookmarks.createBookmark({+ url: "https://example.com/shared-article",+ type: BookmarkTypes.LINK,+ });++ // Owner creates a list and adds the bookmark+ const list = await ownerApi.lists.create({+ name: "Shared Reading List",+ icon: "📚",+ type: "manual",+ });++ await ownerApi.lists.addToList({+ listId: list.id,+ bookmarkId: bookmark.id,+ });++ // Share the list with collaborator+ const collaboratorUser = await collaboratorApi.users.whoami();+ const { invitationId } = await ownerApi.lists.addCollaborator({+ listId: list.id,+ email: collaboratorUser.email!,+ role: "viewer",+ });+ await collaboratorApi.lists.acceptInvitation({ invitationId });++ // Collaborator saves their own reading progress on the shared bookmark+ await collaboratorApi.bookmarks.updateReadingProgress({+ bookmarkId: bookmark.id,+ readingProgressOffset: 2500,+ readingProgressAnchor: "Collaborator's position",+ });++ // Collaborator retrieves their progress+ const collaboratorProgress =+ await collaboratorApi.bookmarks.getReadingProgress({+ bookmarkId: bookmark.id,+ });+ expect(collaboratorProgress.readingProgressOffset).toBe(2500);+ expect(collaboratorProgress.readingProgressAnchor).toBe(+ "Collaborator's position",+ );++ // Owner's progress should be independent (null since owner hasn't set any)+ const ownerProgress = await ownerApi.bookmarks.getReadingProgress({+ bookmarkId: bookmark.id,+ });+ expect(ownerProgress.readingProgressOffset).toBeNull();+ });++ test<CustomTestContext>("user without shared access cannot save reading progress", async ({+ apiCallers,+ }) => {+ const ownerApi = apiCallers[0];+ const unauthorizedApi = apiCallers[1];++ // Owner creates a bookmark (not shared with anyone)+ const bookmark = await ownerApi.bookmarks.createBookmark({+ url: "https://example.com/private-article",+ type: BookmarkTypes.LINK,+ });++ // Unauthorized user tries to save reading progress+ await expect(() =>+ unauthorizedApi.bookmarks.updateReadingProgress({+ bookmarkId: bookmark.id,+ readingProgressOffset: 1000,+ }),+ ).rejects.toThrow(/Bookmark not found/);+ });++ test<CustomTestContext>("owner and collaborator have independent reading progress on same bookmark", async ({+ apiCallers,+ }) => {+ const ownerApi = apiCallers[0];+ const collaboratorApi = apiCallers[1];++ // Owner creates a link bookmark+ const bookmark = await ownerApi.bookmarks.createBookmark({+ url: "https://example.com/shared-reading",+ type: BookmarkTypes.LINK,+ });++ // Owner creates a list and adds the bookmark+ const list = await ownerApi.lists.create({+ name: "Shared List",+ icon: "📚",+ type: "manual",+ });++ await ownerApi.lists.addToList({+ listId: list.id,+ bookmarkId: bookmark.id,+ });++ // Share with collaborator+ const collaboratorUser = await collaboratorApi.users.whoami();+ const { invitationId } = await ownerApi.lists.addCollaborator({+ listId: list.id,+ email: collaboratorUser.email!,+ role: "viewer",+ });+ await collaboratorApi.lists.acceptInvitation({ invitationId });++ // Owner saves progress at position 1000+ await ownerApi.bookmarks.updateReadingProgress({+ bookmarkId: bookmark.id,+ readingProgressOffset: 1000,+ readingProgressAnchor: "Owner position",+ });++ // Collaborator saves progress at position 5000+ await collaboratorApi.bookmarks.updateReadingProgress({+ bookmarkId: bookmark.id,+ readingProgressOffset: 5000,+ readingProgressAnchor: "Collaborator position",+ });++ // Verify each user sees their own progress+ const ownerProgress = await ownerApi.bookmarks.getReadingProgress({+ bookmarkId: bookmark.id,+ });+ const collaboratorProgress =+ await collaboratorApi.bookmarks.getReadingProgress({+ bookmarkId: bookmark.id,+ });++ expect(ownerProgress.readingProgressOffset).toBe(1000);+ expect(ownerProgress.readingProgressAnchor).toBe("Owner position");++ expect(collaboratorProgress.readingProgressOffset).toBe(5000);+ expect(collaboratorProgress.readingProgressAnchor).toBe(+ "Collaborator position",+ );+ });+ });});diff --git a/packages/trpc/routers/bookmarks.ts b/packages/trpc/routers/bookmarks.tsindex 61902ddf..159e12c4 100644--- a/packages/trpc/routers/bookmarks.ts+++ b/packages/trpc/routers/bookmarks.ts@@ -14,6 +14,7 @@ import {bookmarkTexts,customPrompts,tagsOnBookmarks,+ userReadingProgress,users,} from "@karakeep/db/schema";import {@@ -46,6 +47,7 @@ import {zSearchBookmarksRequestSchema,zUpdateBookmarksRequestSchema,} from "@karakeep/shared/types/bookmarks";+import { ANCHOR_TEXT_MAX_LENGTH } from "@karakeep/shared/utils/reading-progress-dom";import { normalizeTagName } from "@karakeep/shared/utils/tag";import type { AuthedContext } from "../index";@@ -582,6 +584,67 @@ export const bookmarksAppRouter = router({},);}),+ updateReadingProgress: authedProcedure+ .input(+ z.object({+ bookmarkId: z.string(),+ readingProgressOffset: z.number().int().nonnegative(),+ readingProgressAnchor: z.string().max(ANCHOR_TEXT_MAX_LENGTH).nullish(),+ readingProgressPercent: z.number().int().min(0).max(100).nullish(),+ }),+ )+ .use(ensureBookmarkAccess)+ .mutation(async ({ input, ctx }) => {+ // Validate this is a LINK bookmark - reading progress only applies to links+ const linkBookmark = await ctx.db.query.bookmarkLinks.findFirst({+ where: eq(bookmarkLinks.id, input.bookmarkId),+ });+ if (!linkBookmark) {+ throw new TRPCError({+ code: "BAD_REQUEST",+ message: "Reading progress can only be saved for link bookmarks",+ });+ }++ await ctx.db+ .insert(userReadingProgress)+ .values({+ bookmarkId: input.bookmarkId,+ userId: ctx.user.id,+ readingProgressOffset: input.readingProgressOffset,+ readingProgressAnchor: input.readingProgressAnchor ?? null,+ readingProgressPercent: input.readingProgressPercent ?? null,+ })+ .onConflictDoUpdate({+ target: [userReadingProgress.bookmarkId, userReadingProgress.userId],+ set: {+ readingProgressOffset: input.readingProgressOffset,+ readingProgressAnchor: input.readingProgressAnchor ?? null,+ readingProgressPercent: input.readingProgressPercent ?? null,+ modifiedAt: new Date(),+ },+ });+ }),+ getReadingProgress: authedProcedure+ .input(+ z.object({+ bookmarkId: z.string(),+ }),+ )+ .use(ensureBookmarkAccess)+ .query(async ({ input, ctx }) => {+ const progress = await ctx.db.query.userReadingProgress.findFirst({+ where: and(+ eq(userReadingProgress.bookmarkId, input.bookmarkId),+ eq(userReadingProgress.userId, ctx.user.id),+ ),+ });+ return {+ readingProgressOffset: progress?.readingProgressOffset ?? null,+ readingProgressAnchor: progress?.readingProgressAnchor ?? null,+ readingProgressPercent: progress?.readingProgressPercent ?? null,+ };+ }),getBookmark: authedProcedure.input(z.object({