Do not b64 encode/decode since lufi-api handles that already. Do not read the file since it's not needed

This commit is contained in:
Booteille 2024-08-01 17:07:08 +02:00
parent 77a0d12920
commit 0f33341b73
No known key found for this signature in database
GPG Key ID: 0AB6C6CA01272646
2 changed files with 6 additions and 35 deletions

View File

@ -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 });

View File

@ -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))
}
}