Skip to content

Build your personal knowledge base with Trilium Notes

fix(server): build errors after newer types

Elian Doran17884558ad62
diff --git a/src/services/encryption/data_encryption.ts b/src/services/encryption/data_encryption.ts
index 285462d898..624a845ede 100644
--- a/src/services/encryption/data_encryption.ts
+++ b/src/services/encryption/data_encryption.ts
@@ -34,7 +34,7 @@ function encrypt(key: Buffer, plainText: Buffer | string) {
throw new Error("No data key!");
}
- const plainTextBuffer = Buffer.from(plainText);
+ const plainTextBuffer = Buffer.isBuffer(plainText) ? plainText : Buffer.from(plainText);
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv("aes-128-cbc", pad(key), pad(iv));
@@ -88,7 +88,7 @@ function decrypt(key: Buffer, cipherText: string | Buffer): Buffer | false | nul
if (e.message?.includes("WRONG_FINAL_BLOCK_LENGTH") || e.message?.includes("wrong final block length")) {
log.info("Caught WRONG_FINAL_BLOCK_LENGTH, returning cipherText instead");
- return Buffer.from(cipherText);
+ return (Buffer.isBuffer(cipherText) ? cipherText : Buffer.from(cipherText));
} else {
throw e;
}
diff --git a/src/services/utils.ts b/src/services/utils.ts
index a2e5da3f61..6c539f9de3 100644
--- a/src/services/utils.ts
+++ b/src/services/utils.ts
@@ -57,7 +57,8 @@ export function hashedBlobId(content: string | Buffer) {
}
export function toBase64(plainText: string | Buffer) {
- return Buffer.from(plainText).toString("base64");
+ const buffer = (Buffer.isBuffer(plainText) ? plainText : Buffer.from(plainText));
+ return buffer.toString("base64");
}
export function fromBase64(encodedText: string) {