From 17884558ad6292774a30518cfc5db8bc37776c2e Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 1 Mar 2025 10:16:24 +0200 Subject: [PATCH] fix(server): build errors after newer types --- src/services/encryption/data_encryption.ts | 4 ++-- src/services/utils.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/services/encryption/data_encryption.ts b/src/services/encryption/data_encryption.ts index 285462d89..624a845ed 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 a2e5da3f6..6c539f9de 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) {