Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(server): remove Blob interface in favor of BlobRow
Elian Doran01f3c32d9228
diff --git a/apps/server/src/services/blob-interface.ts b/apps/server/src/services/blob-interface.tsdeleted file mode 100644index a0e6052785..0000000000--- 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.tsindex 7d0b53e574..65c941e1c5 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<Blob>("SELECT blobId, content, utcDateModified FROM blobs WHERE blobId = ?", [entityId]);+ const blob = sql.getRow<Pick<BlobRow, "blobId" | "content" | "utcDateModified">>("SELECT blobId, content, utcDateModified FROM blobs WHERE blobId = ?", [entityId]);ec.hash = blobService.calculateContentHash(blob);ec.utcDateChanged = blob.utcDateModified;ec.isSynced = true; // blobs are always synceddiff --git a/apps/server/src/share/shaca/entities/sattachment.ts b/apps/server/src/share/shaca/entities/sattachment.tsindex 11d3af0969..1f4f1ae90d 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<Pick<Blob, "content">>(/*sql*/`SELECT content FROM blobs WHERE blobId = ?`, [this.blobId]);+ const row = sql.getRow<Pick<BlobRow, "content">>(/*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.tsindex ecc1d31917..6f0b9c8c6d 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<Pick<Blob, "content">>(/*sql*/`SELECT content FROM blobs WHERE blobId = ?`, [this.blobId]);+ const row = sql.getRow<Pick<BlobRow, "content">>(/*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.tsindex bdf04e01c8..9de989abcd 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: booleareturn content;}-function calculateContentHash({ blobId, content }: Blob) {+function calculateContentHash({ blobId, content }: Pick<BlobRow, "blobId" | "content">) {return hash(`${blobId}|${content.toString()}`);}