From 29608099db227b0a8a130175b6d1969ac334dcf6 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Wed, 22 Mar 2023 09:30:12 +0500 Subject: [PATCH] web: `writeEncrypted` -> `writeEncryptedBase64` --- apps/web/src/interfaces/fs.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/web/src/interfaces/fs.js b/apps/web/src/interfaces/fs.js index 4852f438d..d662c7759 100644 --- a/apps/web/src/interfaces/fs.js +++ b/apps/web/src/interfaces/fs.js @@ -98,18 +98,19 @@ async function writeEncryptedFile(file, key, hash) { /** * We perform 4 steps here: - * 1. We convert base64 to Uint8Array (if we get base64, that is) + * 1. We convert base64 to Uint8Array * 2. We hash the Uint8Array. * 3. We encrypt the Uint8Array * 4. We save the encrypted Uint8Array */ -async function writeEncrypted(filename, { data, type, key, mimeType }) { - if (type === "base64") data = new Uint8Array(Buffer.from(data, "base64")); +async function writeEncryptedBase64(metadata) { + const { data, key, mimeType } = metadata; - const { hash, type: hashType } = await hashBuffer(data); - if (!filename) filename = hash; + const bytes = new Uint8Array(Buffer.from(data, "base64")); - const file = new File([data.buffer], filename, { + const { hash, type: hashType } = await hashBuffer(bytes); + + const file = new File([bytes.buffer], hash, { type: mimeType || "application/octet-stream" }); @@ -461,7 +462,7 @@ function clearFileStorage() { } const FS = { - writeEncrypted, + writeEncryptedBase64, readEncrypted, uploadFile: cancellable(uploadFile), downloadFile: cancellable(downloadFile),