From 4fdea77c5729974e730d0aa53c1b8cf6be85c424 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 19 Jan 2020 09:01:51 +0100 Subject: [PATCH] fix setting contentLength --- src/entities/note.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/entities/note.js b/src/entities/note.js index 070d9d4b4..8a7cf219b 100644 --- a/src/entities/note.js +++ b/src/entities/note.js @@ -123,9 +123,11 @@ class Note extends Entity { throw new Error(`Cannot set null content to note ${this.noteId}`); } + content = Buffer.isBuffer(content) ? content : Buffer.from(content); + // force updating note itself so that dateModified is represented correctly even for the content this.forcedChange = true; - this.contentLength = content.length; + this.contentLength = content.byteLength; await this.save(); this.content = content; @@ -134,7 +136,7 @@ class Note extends Entity { noteId: this.noteId, content: content, utcDateModified: dateUtils.utcNowDateTime(), - hash: utils.hash(this.noteId + "|" + content) + hash: utils.hash(this.noteId + "|" + content.toString()) }; if (this.isProtected) {