Skip to content

Build your personal knowledge base with Trilium Notes

fix(standalone): sync crashing due to use of Buffer

Elian Doranf5f11de58e67
diff --git a/packages/trilium-core/src/services/sync.ts b/packages/trilium-core/src/services/sync.ts
index 57b44bbdcb..12c76e9cf7 100644
--- a/packages/trilium-core/src/services/sync.ts
+++ b/packages/trilium-core/src/services/sync.ts
@@ -360,7 +360,7 @@ function getEntityChangeRow(entityChange: EntityChange) {
if (entityName === "blobs" && entityRow.content !== null) {
if (typeof entityRow.content === "string") {
- entityRow.content = Buffer.from(entityRow.content, "utf-8");
+ entityRow.content = binary_utils.encodeUtf8(entityRow.content);
}
if (entityRow.content) {
diff --git a/packages/trilium-core/src/services/sync_update.ts b/packages/trilium-core/src/services/sync_update.ts
index 2d13c8cdbb..233ceba514 100644
--- a/packages/trilium-core/src/services/sync_update.ts
+++ b/packages/trilium-core/src/services/sync_update.ts
@@ -6,6 +6,7 @@ import { getSql } from "./sql/index.js";
import ws from "./ws.js";
import { default as eventService } from "./events.js";
import entity_constructor from "../becca/entity_constructor.js";
+import { decodeBase64 } from "./utils/binary.js";
interface UpdateContext {
alreadyErased: number;
@@ -119,7 +120,7 @@ function preProcessContent(remoteEC: EntityChange, remoteEntityRow: EntityRow) {
// "string notes". The problem is that in general, it's not possible to detect whether a blob content
// is string note or note (syncs can arrive out of order)
if (typeof remoteEntityRow.content === "string") {
- remoteEntityRow.content = Buffer.from(remoteEntityRow.content, "base64");
+ remoteEntityRow.content = decodeBase64(remoteEntityRow.content);
if (remoteEntityRow.content.byteLength === 0) {
// there seems to be a bug which causes empty buffer to be stored as NULL which is then picked up as inconsistency
diff --git a/packages/trilium-core/src/services/utils/binary.ts b/packages/trilium-core/src/services/utils/binary.ts
index 54b734ca76..34b2909b9a 100644
--- a/packages/trilium-core/src/services/utils/binary.ts
+++ b/packages/trilium-core/src/services/utils/binary.ts
@@ -41,7 +41,7 @@ export function decodeUtf8(stringOrBuffer: string | Uint8Array) {
}
export function encodeUtf8(string: string | Uint8Array) {
- return utf8Encoder.encode(wrapStringOrBuffer(string));
+ return utf8Encoder.encode(unwrapStringOrBuffer(string));
}
export function unwrapStringOrBuffer(stringOrBuffer: string | Uint8Array) {