From 01f3c32d9228489df7418288e54cf9823d2d57c3 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 6 Jan 2026 12:24:09 +0200 Subject: [PATCH] refactor(server): remove Blob interface in favor of BlobRow --- apps/server/src/services/blob-interface.ts | 5 ---- apps/server/src/services/entity_changes.ts | 5 ++-- .../src/share/shaca/entities/sattachment.ts | 23 ++++++++++--------- apps/server/src/share/shaca/entities/snote.ts | 4 ++-- packages/trilium-core/src/services/blob.ts | 4 ++-- 5 files changed, 18 insertions(+), 23 deletions(-) delete mode 100644 apps/server/src/services/blob-interface.ts diff --git a/apps/server/src/services/blob-interface.ts b/apps/server/src/services/blob-interface.ts deleted file mode 100644 index a0e605278..000000000 --- a/apps/server/src/services/blob-interface.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface Blob { - blobId: string; - content: string | Buffer; - utcDateModified: string; -} diff --git a/apps/server/src/services/entity_changes.ts b/apps/server/src/services/entity_changes.ts index 7d0b53e57..65c941e1c 100644 --- a/apps/server/src/services/entity_changes.ts +++ b/apps/server/src/services/entity_changes.ts @@ -1,8 +1,7 @@ -import type { EntityChange } from "@triliumnext/commons"; +import type { BlobRow, EntityChange } from "@triliumnext/commons"; import { blob as blobService, events as eventService } from "@triliumnext/core"; import becca from "../becca/becca.js"; -import type { Blob } from "./blob-interface.js"; import cls from "./cls.js"; import dateUtils from "./date_utils.js"; import instanceId from "./instance_id.js"; @@ -146,7 +145,7 @@ function fillEntityChanges(entityName: string, entityPrimaryKey: string, conditi }; if (entityName === "blobs") { - const blob = sql.getRow("SELECT blobId, content, utcDateModified FROM blobs WHERE blobId = ?", [entityId]); + const blob = sql.getRow>("SELECT blobId, content, utcDateModified FROM blobs WHERE blobId = ?", [entityId]); ec.hash = blobService.calculateContentHash(blob); ec.utcDateChanged = blob.utcDateModified; ec.isSynced = true; // blobs are always synced diff --git a/apps/server/src/share/shaca/entities/sattachment.ts b/apps/server/src/share/shaca/entities/sattachment.ts index 11d3af096..1f4f1ae90 100644 --- a/apps/server/src/share/shaca/entities/sattachment.ts +++ b/apps/server/src/share/shaca/entities/sattachment.ts @@ -1,11 +1,12 @@ -"use strict"; -import sql from "../../sql.js"; + +import { BlobRow } from "@triliumnext/commons"; + import utils from "../../../services/utils.js"; +import sql from "../../sql.js"; import AbstractShacaEntity from "./abstract_shaca_entity.js"; -import type SNote from "./snote.js"; -import type { Blob } from "../../../services/blob-interface.js"; import type { SAttachmentRow } from "./rows.js"; +import type SNote from "./snote.js"; class SAttachment extends AbstractShacaEntity { private attachmentId: string; @@ -37,23 +38,23 @@ class SAttachment extends AbstractShacaEntity { } getContent(silentNotFoundError = false) { - const row = sql.getRow>(/*sql*/`SELECT content FROM blobs WHERE blobId = ?`, [this.blobId]); + const row = sql.getRow>(/*sql*/`SELECT content FROM blobs WHERE blobId = ?`, [this.blobId]); if (!row) { if (silentNotFoundError) { return undefined; - } else { - throw new Error(`Cannot find blob for attachment '${this.attachmentId}', blob '${this.blobId}'`); - } + } + throw new Error(`Cannot find blob for attachment '${this.attachmentId}', blob '${this.blobId}'`); + } const content = row.content; if (this.hasStringContent()) { return content === null ? "" : content.toString("utf-8"); - } else { - return content; - } + } + return content; + } /** @returns true if the attachment has string content (not binary) */ diff --git a/apps/server/src/share/shaca/entities/snote.ts b/apps/server/src/share/shaca/entities/snote.ts index ecc1d3191..6f0b9c8c6 100644 --- a/apps/server/src/share/shaca/entities/snote.ts +++ b/apps/server/src/share/shaca/entities/snote.ts @@ -1,7 +1,7 @@ +import { BlobRow } from "@triliumnext/commons"; import { NOTE_TYPE_ICONS } from "@triliumnext/core"; import escape from "escape-html"; -import type { Blob } from "../../../services/blob-interface.js"; import utils from "../../../services/utils.js"; import sql from "../../sql.js"; import AbstractShacaEntity from "./abstract_shaca_entity.js"; @@ -95,7 +95,7 @@ class SNote extends AbstractShacaEntity { } getContent(silentNotFoundError = false) { - const row = sql.getRow>(/*sql*/`SELECT content FROM blobs WHERE blobId = ?`, [this.blobId]); + const row = sql.getRow>(/*sql*/`SELECT content FROM blobs WHERE blobId = ?`, [this.blobId]); if (!row) { if (silentNotFoundError) { diff --git a/packages/trilium-core/src/services/blob.ts b/packages/trilium-core/src/services/blob.ts index bdf04e01c..9de989abc 100644 --- a/packages/trilium-core/src/services/blob.ts +++ b/packages/trilium-core/src/services/blob.ts @@ -1,6 +1,6 @@ +import { BlobRow } from "@triliumnext/commons"; import becca from "../becca/becca.js"; import { NotFoundError } from "../errors"; -import type { Blob } from "./blob-interface.js"; import protectedSessionService from "./protected_session.js"; import { hash } from "./utils.js"; import { decodeUtf8 } from "./utils/binary.js"; @@ -52,7 +52,7 @@ function processContent(content: Uint8Array | string | null, isProtected: boolea return content; } -function calculateContentHash({ blobId, content }: Blob) { +function calculateContentHash({ blobId, content }: Pick) { return hash(`${blobId}|${content.toString()}`); }