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:
parent
77a0d12920
commit
0f33341b73
|
@ -35,18 +35,6 @@ function pageKey() {
|
||||||
return key;
|
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
|
// Something's wring
|
||||||
function addAlert(msg) {
|
function addAlert(msg) {
|
||||||
$('#please-wait').remove();
|
$('#please-wait').remove();
|
||||||
|
@ -124,9 +112,7 @@ function spawnWebsocket(pa) {
|
||||||
$('#pbt').html(`${percent}%`);
|
$('#pbt').html(`${percent}%`);
|
||||||
try {
|
try {
|
||||||
lufiApi.lufiCrypto.decrypt(window.key, slice).then((decrypted) => {
|
lufiApi.lufiCrypto.decrypt(window.key, slice).then((decrypted) => {
|
||||||
var b64 = decrypted;
|
window.a[data.part] = decrypted;
|
||||||
|
|
||||||
window.a[data.part] = base64ToArrayBuffer(b64);
|
|
||||||
|
|
||||||
if (data.part + 1 === data.total) {
|
if (data.part + 1 === data.total) {
|
||||||
var blob = new Blob(a, { type: data.type });
|
var blob = new Blob(a, { type: data.type });
|
||||||
|
|
|
@ -357,23 +357,12 @@ function sliceAndUpload(randomKey, i, parts, j, delay, del_at_first_view, short,
|
||||||
} else {
|
} else {
|
||||||
var file = window.fileList[i];
|
var file = window.fileList[i];
|
||||||
var slice = file.slice(j * window.sliceLength, (j + 1) * window.sliceLength, file.type);
|
var slice = file.slice(j * window.sliceLength, (j + 1) * window.sliceLength, file.type);
|
||||||
var fr = new FileReader();
|
|
||||||
|
|
||||||
fr.onloadend = function() {
|
slice.arrayBuffer().then((sliceArrayBuffer) => {
|
||||||
var sl = $(`#parts-${window.fc}`);
|
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);
|
|
||||||
|
|
||||||
// Encrypt it
|
// Encrypt it
|
||||||
lufiApi.lufiCrypto.encrypt(randomKey, new TextEncoder().encode(b).buffer).then((encryptedFile) => {
|
lufiApi.lufiCrypto.encrypt(randomKey, sliceArrayBuffer).then((encryptedFile) => {
|
||||||
let encrypted = encryptedFile;
|
let encrypted = encryptedFile;
|
||||||
|
|
||||||
// Prepare json
|
// Prepare json
|
||||||
|
@ -431,12 +420,8 @@ function sliceAndUpload(randomKey, i, parts, j, delay, del_at_first_view, short,
|
||||||
|
|
||||||
window.ws.send(data);
|
window.ws.send(data);
|
||||||
}
|
}
|
||||||
}).catch((e) => {
|
}).catch((e) => console.error(e))
|
||||||
console.error(e);
|
}).catch((e) => console.error(e))
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fr.readAsBinaryString(slice);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue