A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
feat: Add per user storage quota
Mohamed Bassem384432d31e7b
diff --git a/apps/web/components/admin/UpdateUserDialog.tsx b/apps/web/components/admin/UpdateUserDialog.tsxindex 82a239ca..7093ccda 100644--- a/apps/web/components/admin/UpdateUserDialog.tsx+++ b/apps/web/components/admin/UpdateUserDialog.tsx@@ -41,12 +41,14 @@ interface UpdateUserDialogProps {userId: string;currentRole: "user" | "admin";currentQuota: number | null;+ currentStorageQuota: number | null;children?: React.ReactNode;}export default function UpdateUserDialog({userId,currentRole,currentQuota,+ currentStorageQuota,children,}: UpdateUserDialogProps) {const apiUtils = api.useUtils();@@ -55,6 +57,7 @@ export default function UpdateUserDialog({userId,role: currentRole,bookmarkQuota: currentQuota,+ storageQuota: currentStorageQuota,};const form = useForm<UpdateUserSchema>({resolver: zodResolver(updateUserSchema),@@ -147,6 +150,29 @@ export default function UpdateUserDialog({</FormItem>)}/>+ <FormField+ control={form.control}+ name="storageQuota"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Storage Quota (bytes)</FormLabel>+ <FormControl>+ <Input+ type="number"+ min="0"+ placeholder="Unlimited (leave empty)"+ {...field}+ value={field.value ?? ""}+ onChange={(e) => {+ const value = e.target.value;+ field.onChange(value === "" ? null : parseInt(value));+ }}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ /><FormFieldcontrol={form.control}name="userId"diff --git a/apps/web/components/admin/UserList.tsx b/apps/web/components/admin/UserList.tsxindex a3b4d94f..2dd86277 100644--- a/apps/web/components/admin/UserList.tsx+++ b/apps/web/components/admin/UserList.tsx@@ -72,6 +72,7 @@ export default function UsersSection() {<TableHead>{t("common.email")}</TableHead><TableHead>{t("admin.users_list.num_bookmarks")}</TableHead><TableHead>{t("common.quota")}</TableHead>+ <TableHead>Storage Quota</TableHead><TableHead>{t("admin.users_list.asset_sizes")}</TableHead><TableHead>{t("common.role")}</TableHead><TableHead>{t("admin.users_list.local_user")}</TableHead>@@ -88,6 +89,11 @@ export default function UsersSection() {<TableCell className="py-1">{u.bookmarkQuota ?? t("admin.users_list.unlimited")}</TableCell>+ <TableCell className="py-1">+ {u.storageQuota+ ? toHumanReadableSize(u.storageQuota)+ : t("admin.users_list.unlimited")}+ </TableCell><TableCell className="py-1">{toHumanReadableSize(userStats[u.id].assetSizes)}</TableCell>@@ -140,6 +146,7 @@ export default function UsersSection() {userId={u.id}currentRole={u.role!}currentQuota={u.bookmarkQuota}+ currentStorageQuota={u.storageQuota}><ButtonWithTooltiptooltip="Edit User"diff --git a/apps/workers/workerUtils.ts b/apps/workers/workerUtils.tsindex 44180951..d41df578 100644--- a/apps/workers/workerUtils.ts+++ b/apps/workers/workerUtils.ts@@ -4,7 +4,6 @@ import { db, KarakeepDBTransaction } from "@karakeep/db";import { assets, AssetTypes, bookmarks } from "@karakeep/db/schema";type DBAssetType = typeof assets.$inferInsert;-export async function updateAsset(oldAssetId: string | undefined,newAsset: DBAssetType,diff --git a/apps/workers/workers/assetPreprocessingWorker.ts b/apps/workers/workers/assetPreprocessingWorker.tsindex d43163ac..8231ce50 100644--- a/apps/workers/workers/assetPreprocessingWorker.ts+++ b/apps/workers/workers/assetPreprocessingWorker.ts@@ -21,6 +21,10 @@ import {OpenAIQueue,triggerSearchReindex,} from "@karakeep/shared/queues";+import {+ checkStorageQuota,+ StorageQuotaError,+} from "@karakeep/trpc/lib/storageQuota";export class AssetPreprocessingWorker {static build() {@@ -128,6 +132,13 @@ export async function extractAndSavePDFScreenshot(return false;}+ // Check storage quota before inserting+ const quotaApproved = await checkStorageQuota(+ db,+ bookmark.userId,+ screenshot.buffer.byteLength,+ );+// Store the screenshotconst assetId = newAssetId();const fileName = "screenshot.png";@@ -140,6 +151,7 @@ export async function extractAndSavePDFScreenshot(contentType,fileName,},+ quotaApproved,});// Insert into database@@ -158,6 +170,12 @@ export async function extractAndSavePDFScreenshot();return true;} catch (error) {+ if (error instanceof StorageQuotaError) {+ logger.warn(+ `[assetPreprocessing][${jobId}] Skipping PDF screenshot due to quota exceeded: ${error.message}`,+ );+ return true; // Return true to indicate the job completed successfully, just skipped the asset+ }logger.error(`[assetPreprocessing][${jobId}] Failed to process PDF screenshot: ${error}`,);diff --git a/apps/workers/workers/crawlerWorker.ts b/apps/workers/workers/crawlerWorker.tsindex 7d92eb51..10106a3b 100644--- a/apps/workers/workers/crawlerWorker.ts+++ b/apps/workers/workers/crawlerWorker.ts@@ -61,6 +61,10 @@ import {zCrawlLinkRequestSchema,} from "@karakeep/shared/queues";import { BookmarkTypes } from "@karakeep/shared/types/bookmarks";+import {+ checkStorageQuota,+ StorageQuotaError,+} from "@karakeep/trpc/lib/storageQuota";import metascraperReddit from "../metascraper-plugins/metascraper-reddit";@@ -435,16 +439,35 @@ async function storeScreenshot(const assetId = newAssetId();const contentType = "image/png";const fileName = "screenshot.png";- await saveAsset({- userId,- assetId,- metadata: { contentType, fileName },- asset: screenshot,- });- logger.info(- `[Crawler][${jobId}] Stored the screenshot as assetId: ${assetId}`,- );- return { assetId, contentType, fileName, size: screenshot.byteLength };++ // Check storage quota before saving the screenshot+ try {+ const quotaApproved = await checkStorageQuota(+ db,+ userId,+ screenshot.byteLength,+ );++ await saveAsset({+ userId,+ assetId,+ metadata: { contentType, fileName },+ asset: screenshot,+ quotaApproved,+ });+ logger.info(+ `[Crawler][${jobId}] Stored the screenshot as assetId: ${assetId}`,+ );+ return { assetId, contentType, fileName, size: screenshot.byteLength };+ } catch (error) {+ if (error instanceof StorageQuotaError) {+ logger.warn(+ `[Crawler][${jobId}] Skipping screenshot storage due to quota exceeded: ${error.message}`,+ );+ return null;+ }+ throw error;+ }}async function downloadAndStoreFile(@@ -470,11 +493,19 @@ async function downloadAndStoreFile(throw new Error("No content type in the response");}+ // Check storage quota before saving the asset+ const quotaApproved = await checkStorageQuota(+ db,+ userId,+ buffer.byteLength,+ );+await saveAsset({userId,assetId,metadata: { contentType },asset: Buffer.from(buffer),+ quotaApproved,});logger.info(@@ -483,6 +514,12 @@ async function downloadAndStoreFile(return { assetId, userId, contentType, size: buffer.byteLength };} catch (e) {+ if (e instanceof StorageQuotaError) {+ logger.warn(+ `[Crawler][${jobId}] Skipping ${fileType} storage due to quota exceeded: ${e.message}`,+ );+ return null;+ }logger.error(`[Crawler][${jobId}] Failed to download and store ${fileType}: ${e}`,);@@ -523,24 +560,52 @@ async function archiveWebpage(const contentType = "text/html";- await saveAssetFromFile({- userId,- assetId,- assetPath,- metadata: {- contentType,- },- });+ // Get file size and check quota before saving+ const stats = await fs.stat(assetPath);+ const fileSize = stats.size;- logger.info(- `[Crawler][${jobId}] Done archiving the page as assetId: ${assetId}`,- );+ try {+ const quotaApproved = await checkStorageQuota(db, userId, fileSize);- return {- assetId,- contentType,- size: await getAssetSize({ userId, assetId }),- };+ await saveAssetFromFile({+ userId,+ assetId,+ assetPath,+ metadata: {+ contentType,+ },+ quotaApproved,+ });++ logger.info(+ `[Crawler][${jobId}] Done archiving the page as assetId: ${assetId}`,+ );++ return {+ assetId,+ contentType,+ size: await getAssetSize({ userId, assetId }),+ };+ } catch (error) {+ if (error instanceof StorageQuotaError) {+ logger.warn(+ `[Crawler][${jobId}] Skipping page archive storage due to quota exceeded: ${error.message}`,+ );+ // Clean up the temporary file+ try {+ await fs.unlink(assetPath);+ logger.info(+ `[Crawler][${jobId}] Cleaned up temporary archive file: ${assetPath}`,+ );+ } catch (cleanupError) {+ logger.warn(+ `[Crawler][${jobId}] Failed to clean up temporary archive file: ${cleanupError}`,+ );+ }+ return null;+ }+ throw error;+ }}async function getContentType(@@ -761,11 +826,7 @@ async function crawlAndParseUrl(!precrawledArchiveAssetId &&(serverConfig.crawler.fullPageArchive || archiveFullPage)) {- const {- assetId: fullPageArchiveAssetId,- size,- contentType,- } = await archiveWebpage(+ const archiveResult = await archiveWebpage(htmlContent,browserUrl,userId,@@ -773,23 +834,31 @@ async function crawlAndParseUrl(abortSignal,);- await db.transaction(async (txn) => {- await updateAsset(- oldFullPageArchiveAssetId,- {- id: fullPageArchiveAssetId,- bookmarkId,- userId,- assetType: AssetTypes.LINK_FULL_PAGE_ARCHIVE,- contentType,- size,- fileName: null,- },- txn,- );- });- if (oldFullPageArchiveAssetId) {- silentDeleteAsset(userId, oldFullPageArchiveAssetId);+ if (archiveResult) {+ const {+ assetId: fullPageArchiveAssetId,+ size,+ contentType,+ } = archiveResult;++ await db.transaction(async (txn) => {+ await updateAsset(+ oldFullPageArchiveAssetId,+ {+ id: fullPageArchiveAssetId,+ bookmarkId,+ userId,+ assetType: AssetTypes.LINK_FULL_PAGE_ARCHIVE,+ contentType,+ size,+ fileName: null,+ },+ txn,+ );+ });+ if (oldFullPageArchiveAssetId) {+ silentDeleteAsset(userId, oldFullPageArchiveAssetId);+ }}}};diff --git a/apps/workers/workers/videoWorker.ts b/apps/workers/workers/videoWorker.tsindex ca591e6f..d25c1948 100644--- a/apps/workers/workers/videoWorker.ts+++ b/apps/workers/workers/videoWorker.ts@@ -8,7 +8,6 @@ import { db } from "@karakeep/db";import { AssetTypes } from "@karakeep/db/schema";import {ASSET_TYPES,- getAssetSize,newAssetId,saveAssetFromFile,silentDeleteAsset,@@ -20,6 +19,10 @@ import {ZVideoRequest,zvideoRequestSchema,} from "@karakeep/shared/queues";+import {+ checkStorageQuota,+ StorageQuotaError,+} from "@karakeep/trpc/lib/storageQuota";import { withTimeout } from "../utils";import { getBookmarkDetails, updateAsset } from "../workerUtils";@@ -140,32 +143,51 @@ async function runWorker(job: DequeuedJob<ZVideoRequest>) {logger.info(`[VideoCrawler][${jobId}] Finished downloading a file from "${url}" to "${assetPath}"`,);- await saveAssetFromFile({- userId,- assetId: videoAssetId,- assetPath,- metadata: { contentType: ASSET_TYPES.VIDEO_MP4 },- });-- await db.transaction(async (txn) => {- await updateAsset(- oldVideoAssetId,- {- id: videoAssetId,- bookmarkId,- userId,- assetType: AssetTypes.LINK_VIDEO,- contentType: ASSET_TYPES.VIDEO_MP4,- size: await getAssetSize({ userId, assetId: videoAssetId }),- },- txn,- );- });- await silentDeleteAsset(userId, oldVideoAssetId);- logger.info(- `[VideoCrawler][${jobId}] Finished downloading video from "${url}" and adding it to the database`,- );+ // Get file size and check quota before saving+ const stats = await fs.promises.stat(assetPath);+ const fileSize = stats.size;++ try {+ const quotaApproved = await checkStorageQuota(db, userId, fileSize);++ await saveAssetFromFile({+ userId,+ assetId: videoAssetId,+ assetPath,+ metadata: { contentType: ASSET_TYPES.VIDEO_MP4 },+ quotaApproved,+ });++ await db.transaction(async (txn) => {+ await updateAsset(+ oldVideoAssetId,+ {+ id: videoAssetId,+ bookmarkId,+ userId,+ assetType: AssetTypes.LINK_VIDEO,+ contentType: ASSET_TYPES.VIDEO_MP4,+ size: fileSize,+ },+ txn,+ );+ });+ await silentDeleteAsset(userId, oldVideoAssetId);++ logger.info(+ `[VideoCrawler][${jobId}] Finished downloading video from "${url}" and adding it to the database`,+ );+ } catch (error) {+ if (error instanceof StorageQuotaError) {+ logger.warn(+ `[VideoCrawler][${jobId}] Skipping video storage due to quota exceeded: ${error.message}`,+ );+ await deleteLeftOverAssetFile(jobId, videoAssetId);+ return;+ }+ throw error;+ }}/**diff --git a/packages/api/utils/upload.ts b/packages/api/utils/upload.tsindex daff1fb9..7e322c76 100644--- a/packages/api/utils/upload.ts+++ b/packages/api/utils/upload.ts@@ -12,6 +12,10 @@ import {} from "@karakeep/shared/assetdb";import serverConfig from "@karakeep/shared/config";import { AuthedContext } from "@karakeep/trpc";+import {+ checkStorageQuota,+ StorageQuotaError,+} from "@karakeep/trpc/lib/storageQuota";const MAX_UPLOAD_SIZE_BYTES = serverConfig.maxAssetSizeMb * 1024 * 1024;@@ -42,7 +46,7 @@ export async function uploadAsset(db: AuthedContext["db"],formData: { file: File } | { image: File },): Promise<- | { error: string; status: 400 | 413 }+ | { error: string; status: 400 | 413 | 403 }| {assetId: string;contentType: string;@@ -66,6 +70,16 @@ export async function uploadAsset(return { error: "Asset is too big", status: 413 };}+ let quotaApproved;+ try {+ quotaApproved = await checkStorageQuota(db, user.id, data.size);+ } catch (error) {+ if (error instanceof StorageQuotaError) {+ return { error: error.message, status: 403 };+ }+ throw error;+ }+let tempFilePath: string | undefined;try {@@ -94,6 +108,7 @@ export async function uploadAsset(assetId: assetDb.id,assetPath: tempFilePath,metadata: { contentType, fileName },+ quotaApproved,});return {diff --git a/packages/db/drizzle/0053_storage_quota.sql b/packages/db/drizzle/0053_storage_quota.sqlnew file mode 100644index 00000000..206411a1--- /dev/null+++ b/packages/db/drizzle/0053_storage_quota.sql@@ -0,0 +1 @@+ALTER TABLE `user` ADD `storageQuota` integer;\ No newline at end of filediff --git a/packages/db/drizzle/meta/0053_snapshot.json b/packages/db/drizzle/meta/0053_snapshot.jsonnew file mode 100644index 00000000..267e64d0--- /dev/null+++ b/packages/db/drizzle/meta/0053_snapshot.json@@ -0,0 +1,2043 @@+{+ "version": "6",+ "dialect": "sqlite",+ "id": "6e851770-74a1-4985-886c-42c1183c14c7",+ "prevId": "786712cf-334d-43ab-bf05-8f926364b3e2",+ "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+ },+ "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": {}+ },+ "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+ },+ "content": {+ "name": "content",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "htmlContent": {+ "name": "htmlContent",+ "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+ },+ "createdAt": {+ "name": "createdAt",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {+ "bookmarkTags_name_idx": {+ "name": "bookmarkTags_name_idx",+ "columns": [+ "name"+ ],+ "isUnique": false+ },+ "bookmarkTags_userId_idx": {+ "name": "bookmarkTags_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "bookmarkTags_userId_name_unique": {+ "name": "bookmarkTags_userId_name_unique",+ "columns": [+ "userId",+ "name"+ ],+ "isUnique": true+ },+ "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+ }+ },+ "indexes": {+ "bookmarks_userId_idx": {+ "name": "bookmarks_userId_idx",+ "columns": [+ "userId"+ ],+ "isUnique": false+ },+ "bookmarks_archived_idx": {+ "name": "bookmarks_archived_idx",+ "columns": [+ "archived"+ ],+ "isUnique": false+ },+ "bookmarks_favourited_idx": {+ "name": "bookmarks_favourited_idx",+ "columns": [+ "favourited"+ ],+ "isUnique": false+ },+ "bookmarks_createdAt_idx": {+ "name": "bookmarks_createdAt_idx",+ "columns": [+ "createdAt"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "bookmarks_userId_user_id_fk": {+ "name": "bookmarks_userId_user_id_fk",+ "tableFrom": "bookmarks",+ "tableTo": "user",+ "columnsFrom": [+ "userId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {},+ "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+ }+ },+ "indexes": {+ "bookmarksInLists_bookmarkId_idx": {+ "name": "bookmarksInLists_bookmarkId_idx",+ "columns": [+ "bookmarkId"+ ],+ "isUnique": false+ },+ "bookmarksInLists_listId_idx": {+ "name": "bookmarksInLists_listId_idx",+ "columns": [+ "listId"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "bookmarksInLists_bookmarkId_bookmarks_id_fk": {+ "name": "bookmarksInLists_bookmarkId_bookmarks_id_fk",+ "tableFrom": "bookmarksInLists",+ "tableTo": "bookmarks",+ "columnsFrom": [+ "bookmarkId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "bookmarksInLists_listId_bookmarkLists_id_fk": {+ "name": "bookmarksInLists_listId_bookmarkLists_id_fk",+ "tableFrom": "bookmarksInLists",+ "tableTo": "bookmarkLists",+ "columnsFrom": [+ "listId"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "bookmarksInLists_bookmarkId_listId_pk": {+ "columns": [+ "bookmarkId",+ "listId"+ ],+ "name": "bookmarksInLists_bookmarkId_listId_pk"+ }+ },+ "uniqueConstraints": {},+ "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": {}+ },+ "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_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+ },+ "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": {}+ },+ "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+ }+ },+ "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": {}+ },+ "userSettings": {+ "name": "userSettings",+ "columns": {+ "userId": {+ "name": "userId",+ "type": "text",+ "primaryKey": true,+ "notNull": true,+ "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'"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "userSettings_userId_user_id_fk": {+ "name": "userSettings_userId_user_id_fk",+ "tableFrom": "userSettings",+ "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+ }+ },+ "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 2ef11738..9547d628 100644--- a/packages/db/drizzle/meta/_journal.json+++ b/packages/db/drizzle/meta/_journal.json@@ -372,6 +372,13 @@"when": 1751409503089,"tag": "0052_add_bookmark_quota","breakpoints": true+ },+ {+ "idx": 53,+ "version": "6",+ "when": 1751816757805,+ "tag": "0053_storage_quota",+ "breakpoints": true}]}\ No newline at end of filediff --git a/packages/db/schema.ts b/packages/db/schema.tsindex b9b6120f..e3275d85 100644--- a/packages/db/schema.ts+++ b/packages/db/schema.ts@@ -39,6 +39,7 @@ export const users = sqliteTable("user", {salt: text("salt").notNull().default(""),role: text("role", { enum: ["admin", "user"] }).default("user"),bookmarkQuota: integer("bookmarkQuota"),+ storageQuota: integer("storageQuota"),});export const accounts = sqliteTable(diff --git a/packages/shared/assetdb.ts b/packages/shared/assetdb.tsindex 77050406..7653ca15 100644--- a/packages/shared/assetdb.ts+++ b/packages/shared/assetdb.ts@@ -16,6 +16,7 @@ import { z } from "zod";import serverConfig from "./config";import logger from "./logger";+import { QuotaApproved } from "./storageQuota";const ROOT_PATH = serverConfig.assetsDir;@@ -616,12 +617,22 @@ export async function saveAsset({assetId,asset,metadata,+ quotaApproved,}: {userId: string;assetId: string;asset: Buffer;metadata: z.infer<typeof zAssetMetadataSchema>;+ quotaApproved: QuotaApproved;}) {+ // Verify the quota approval is for the correct user and size+ if (quotaApproved.userId !== userId) {+ throw new Error("Quota approval is for a different user");+ }+ if (quotaApproved.approvedSize < asset.byteLength) {+ throw new Error("Asset size exceeds approved quota");+ }+return defaultAssetStore.saveAsset({ userId, assetId, asset, metadata });}@@ -630,12 +641,22 @@ export async function saveAssetFromFile({assetId,assetPath,metadata,+ quotaApproved,}: {userId: string;assetId: string;assetPath: string;metadata: z.infer<typeof zAssetMetadataSchema>;+ quotaApproved: QuotaApproved;}) {+ // Verify the quota approval is for the correct user+ if (quotaApproved.userId !== userId) {+ throw new Error("Quota approval is for a different user");+ }++ // For file-based saves, we'll verify the file size matches the approved size+ // when the underlying store implementation reads the file+return defaultAssetStore.saveAssetFromFile({userId,assetId,@@ -724,35 +745,3 @@ export async function deleteUserAssets({ userId }: { userId: string }) {export async function* getAllAssets() {yield* defaultAssetStore.getAllAssets();}--export async function storeScreenshot(- screenshot: Buffer | undefined,- userId: string,- jobId: string,-) {- if (!serverConfig.crawler.storeScreenshot) {- logger.info(- `[Crawler][${jobId}] Skipping storing the screenshot as per the config.`,- );- return null;- }- if (!screenshot) {- logger.info(- `[Crawler][${jobId}] Skipping storing the screenshot as it's empty.`,- );- return null;- }- const assetId = newAssetId();- const contentType = "image/png";- const fileName = "screenshot.png";- await saveAsset({- userId,- assetId,- metadata: { contentType, fileName },- asset: screenshot,- });- logger.info(- `[Crawler][${jobId}] Stored the screenshot as assetId: ${assetId}`,- );- return { assetId, contentType, fileName, size: screenshot.byteLength };-}diff --git a/packages/shared/storageQuota.ts b/packages/shared/storageQuota.tsnew file mode 100644index 00000000..6b7441a2--- /dev/null+++ b/packages/shared/storageQuota.ts@@ -0,0 +1,19 @@+/**+ * A token that proves storage quota has been checked and approved.+ * This class cannot be instantiated directly - it can only be created+ * by the checkStorageQuota function.+ */+export class QuotaApproved {+ private constructor(+ public readonly userId: string,+ public readonly approvedSize: number,+ ) {}++ /**+ * Internal method to create a QuotaApproved token.+ * This should only be called by checkStorageQuota.+ */+ static _create(userId: string, approvedSize: number): QuotaApproved {+ return new QuotaApproved(userId, approvedSize);+ }+}diff --git a/packages/shared/types/admin.ts b/packages/shared/types/admin.tsindex 652ee2d3..f4c62af0 100644--- a/packages/shared/types/admin.ts+++ b/packages/shared/types/admin.ts@@ -12,6 +12,7 @@ export const updateUserSchema = z.object({userId: z.string(),role: z.enum(["user", "admin"]).optional(),bookmarkQuota: z.number().int().min(0).nullable().optional(),+ storageQuota: z.number().int().min(0).nullable().optional(),});export const resetPasswordSchema = zdiff --git a/packages/trpc/lib/storageQuota.ts b/packages/trpc/lib/storageQuota.tsnew file mode 100644index 00000000..49b96af8--- /dev/null+++ b/packages/trpc/lib/storageQuota.ts@@ -0,0 +1,57 @@+import { eq, sum } from "drizzle-orm";++import type { DB, KarakeepDBTransaction } from "@karakeep/db";+import { assets, users } from "@karakeep/db/schema";+import { QuotaApproved } from "@karakeep/shared/storageQuota";++export class StorageQuotaError extends Error {+ constructor(+ public readonly currentUsage: number,+ public readonly quota: number,+ public readonly requestedSize: number,+ ) {+ super(+ `Storage quota exceeded. Current usage: ${Math.round(currentUsage / 1024 / 1024)}MB, Quota: ${Math.round(quota / 1024 / 1024)}MB, Requested: ${Math.round(requestedSize / 1024 / 1024)}MB`,+ );+ this.name = "StorageQuotaError";+ }+}++export async function checkStorageQuota(+ db: DB | KarakeepDBTransaction,+ userId: string,+ requestedSize: number,+): Promise<QuotaApproved> {+ const user = await db.query.users.findFirst({+ where: eq(users.id, userId),+ columns: {+ storageQuota: true,+ },+ });++ if (user?.storageQuota === null || user?.storageQuota === undefined) {+ // No quota limit - approve the request+ return QuotaApproved._create(userId, requestedSize);+ }++ const currentUsage = await getCurrentStorageUsage(db, userId);++ if (currentUsage + requestedSize > user.storageQuota) {+ throw new StorageQuotaError(currentUsage, user.storageQuota, requestedSize);+ }++ // Quota check passed - return approval token+ return QuotaApproved._create(userId, requestedSize);+}++export async function getCurrentStorageUsage(+ db: DB | KarakeepDBTransaction,+ userId: string,+): Promise<number> {+ const currentUsageResult = await db+ .select({ totalSize: sum(assets.size) })+ .from(assets)+ .where(eq(assets.userId, userId));++ return Number(currentUsageResult[0]?.totalSize ?? 0);+}diff --git a/packages/trpc/routers/admin.ts b/packages/trpc/routers/admin.tsindex f46e17f2..5e169857 100644--- a/packages/trpc/routers/admin.ts+++ b/packages/trpc/routers/admin.ts@@ -351,6 +351,10 @@ export const adminAppRouter = router({updateData.bookmarkQuota = input.bookmarkQuota;}+ if (input.storageQuota !== undefined) {+ updateData.storageQuota = input.storageQuota;+ }+if (Object.keys(updateData).length === 0) {throw new TRPCError({code: "BAD_REQUEST",diff --git a/packages/trpc/routers/users.ts b/packages/trpc/routers/users.tsindex ea5e6944..3c52b321 100644--- a/packages/trpc/routers/users.ts+++ b/packages/trpc/routers/users.ts@@ -148,6 +148,7 @@ export const usersAppRouter = router({role: z.enum(["user", "admin"]).nullable(),localUser: z.boolean(),bookmarkQuota: z.number().nullable(),+ storageQuota: z.number().nullable(),}),),}),@@ -161,6 +162,7 @@ export const usersAppRouter = router({role: users.role,password: users.password,bookmarkQuota: users.bookmarkQuota,+ storageQuota: users.storageQuota,}).from(users);