From 7aba3fe0b630f8480e89eac52c0a632e94772c5b Mon Sep 17 00:00:00 2001
From: 52funny <47419733+52funny@users.noreply.github.com>
Date: Mon, 22 Jul 2024 18:10:01 +0800
Subject: [PATCH] fix: garbled characters caused by atob (#422)

---
 assets/index.js | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/assets/index.js b/assets/index.js
index 4143021..24883a0 100644
--- a/assets/index.js
+++ b/assets/index.js
@@ -108,7 +108,7 @@ window.addEventListener("DOMContentLoaded", async () => {
     return;
   }
 
-  DATA = JSON.parse(atob($indexData.innerHTML));
+  DATA = JSON.parse(decodeBase64($indexData.innerHTML));
   DIR_EMPTY_NOTE = PARAMS.q ? 'No results' : DATA.dir_exists ? 'Empty folder' : 'Folder will be created when a file is uploaded';
 
   await ready();
@@ -910,3 +910,22 @@ function getEncoding(contentType) {
   }
   return 'utf-8';
 }
+
+// Parsing base64 strings with Unicode characters
+function decodeBase64(base64String) {
+  const binString = atob(base64String);
+  const len = binString.length;
+  const bytes = new Uint8Array(len);
+  const arr = new Uint32Array(bytes.buffer, 0, Math.floor(len / 4));
+  let i = 0;
+  for (; i < arr.length; i++) {
+    arr[i] = binString.charCodeAt(i * 4) |
+             (binString.charCodeAt(i * 4 + 1) << 8) |
+             (binString.charCodeAt(i * 4 + 2) << 16) |
+             (binString.charCodeAt(i * 4 + 3) << 24);
+  }
+  for (i = i * 4; i < len; i++) {
+    bytes[i] = binString.charCodeAt(i);
+  }
+  return new TextDecoder().decode(bytes);
+}