mirror of
https://github.com/zadam/trilium.git
synced 2026-01-18 04:24:23 +01:00
refactor(server): remove Blob interface in favor of BlobRow
This commit is contained in:
parent
05b9e2ec2a
commit
01f3c32d92
@ -1,5 +0,0 @@
|
||||
export interface Blob {
|
||||
blobId: string;
|
||||
content: string | Buffer;
|
||||
utcDateModified: string;
|
||||
}
|
||||
@ -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 synced
|
||||
|
||||
@ -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) */
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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<BlobRow, "blobId" | "content">) {
|
||||
return hash(`${blobId}|${content.toString()}`);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user