diff --git a/themes/default/public/js/lufi-down.js b/themes/default/public/js/lufi-down.js index 9ba9999..386bbf7 100644 --- a/themes/default/public/js/lufi-down.js +++ b/themes/default/public/js/lufi-down.js @@ -35,18 +35,6 @@ function pageKey() { return key; } -function base64ToArrayBuffer(base64) { - base64 = base64 instanceof ArrayBuffer ? new TextDecoder().decode(base64) : base64; // Is it using Lufi API? - - var binary_string = window.atob(base64); - var len = binary_string.length; - var bytes = new Uint8Array(len); - for (var i = 0; i < len; i++) { - bytes[i] = binary_string.charCodeAt(i); - } - return bytes.buffer; -} - // Something's wring function addAlert(msg) { $('#please-wait').remove(); @@ -124,9 +112,7 @@ function spawnWebsocket(pa) { $('#pbt').html(`${percent}%`); try { lufiApi.lufiCrypto.decrypt(window.key, slice).then((decrypted) => { - var b64 = decrypted; - - window.a[data.part] = base64ToArrayBuffer(b64); + window.a[data.part] = decrypted; if (data.part + 1 === data.total) { var blob = new Blob(a, { type: data.type }); diff --git a/themes/default/public/js/lufi-up.js b/themes/default/public/js/lufi-up.js index 9d967fc..69d5c5f 100644 --- a/themes/default/public/js/lufi-up.js +++ b/themes/default/public/js/lufi-up.js @@ -357,23 +357,12 @@ function sliceAndUpload(randomKey, i, parts, j, delay, del_at_first_view, short, } else { var file = window.fileList[i]; var slice = file.slice(j * window.sliceLength, (j + 1) * window.sliceLength, file.type); - var fr = new FileReader(); - fr.onloadend = function() { - var sl = $(`#parts-${window.fc}`); - - // Get the binary result, different result in IE browsers (see default.html.ep line 27:48) - if (isIE == true) { - var bin = fr.content; - } else { - var bin = fr.result; - } - - // Transform it in base64 - var b = window.btoa(bin); + slice.arrayBuffer().then((sliceArrayBuffer) => { + var sl = $(`#parts-${window.fc}`); // Encrypt it - lufiApi.lufiCrypto.encrypt(randomKey, new TextEncoder().encode(b).buffer).then((encryptedFile) => { + lufiApi.lufiCrypto.encrypt(randomKey, sliceArrayBuffer).then((encryptedFile) => { let encrypted = encryptedFile; // Prepare json @@ -431,12 +420,8 @@ function sliceAndUpload(randomKey, i, parts, j, delay, del_at_first_view, short, window.ws.send(data); } - }).catch((e) => { - console.error(e); - }) - } - - fr.readAsBinaryString(slice); + }).catch((e) => console.error(e)) + }).catch((e) => console.error(e)) } }