fix(server): build errors after newer types

This commit is contained in:
Elian Doran
2025-03-01 10:16:24 +02:00
parent 455b2bf338
commit 17884558ad
2 changed files with 4 additions and 3 deletions

View File

@@ -34,7 +34,7 @@ function encrypt(key: Buffer, plainText: Buffer | string) {
throw new Error("No data key!"); 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 iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv("aes-128-cbc", pad(key), pad(iv)); 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")) { 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"); log.info("Caught WRONG_FINAL_BLOCK_LENGTH, returning cipherText instead");
return Buffer.from(cipherText); return (Buffer.isBuffer(cipherText) ? cipherText : Buffer.from(cipherText));
} else { } else {
throw e; throw e;
} }

View File

@@ -57,7 +57,8 @@ export function hashedBlobId(content: string | Buffer) {
} }
export function toBase64(plainText: 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) { export function fromBase64(encodedText: string) {