Formatting

This commit is contained in:
Booteille 2024-08-02 08:07:17 +02:00
parent d071467ea7
commit 3ab54f6dae
No known key found for this signature in database
GPG Key ID: 0FE17AFD5A1F837F
2 changed files with 101 additions and 101 deletions

View File

@ -17,19 +17,19 @@ function pageKey() {
// First, strip everything after the equal sign (=) which signals end of base64 string.
i = key.indexOf('=');
let isb64 = false
if (i>-1) {
if (i > -1) {
key = key.substring(0, i + 1);
isb64 = true
}
// If the equal sign was not present, some parameters may remain:
i = key.indexOf('&'); if (i>-1) { key = key.substring(0, i); }
i = key.indexOf('&'); if (i > -1) { key = key.substring(0, i); }
// Then add trailing equal sign if it's missing and was using the Sjcl algorithm
if (isb64) {
if (key.charAt(key.length-1)!=='=') key += '=';
if (key.charAt(key.length - 1) !== '=') key += '=';
}
return key;
@ -95,16 +95,16 @@ function spawnWebsocket(pa) {
window.attempts = 10;
} else {
console.log(`Getting slice ${data.part + 1} of ${data.total}`);
var slice = JSON.parse(res.shift());
var slice = JSON.parse(res.shift());
// If file was used using Lufi API
if (slice.iv) {
slice.iv = new Uint8Array(Object.values(slice.iv))
}
var percent = Math.round(1000 * (data.part + 1)/data.total)/10;
var wClass = percent.toString().replace('.', '-');
var pb = $('#pb');
var percent = Math.round(1000 * (data.part + 1) / data.total) / 10;
var wClass = percent.toString().replace('.', '-');
var pb = $('#pb');
pb.removeClass();
pb.addClass('determinate');
pb.addClass(`width-${wClass}`);
@ -112,7 +112,7 @@ function spawnWebsocket(pa) {
$('#pbt').html(`${percent}%`);
try {
lufiApi.lufiCrypto.decrypt(window.key, slice).then((decrypted) => {
window.a[data.part] = decrypted;
window.a[data.part] = decrypted;
if (data.part + 1 === data.total) {
var blob = new Blob(a, { type: data.type });
@ -121,43 +121,43 @@ function spawnWebsocket(pa) {
$('#please-wait').remove();
$('#loading').remove();
var pbd = $('#pbd');
pbd.attr('class', 'center-align');
// IE & Edge fix for downloading blob files, gives option to save or open the file when the link is opened.
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
var fileName = escapeHtml(data.name);
window.navigator.msSaveOrOpenBlob(blob, fileName);
} else {
var blobURL = URL.createObjectURL(blob);
}
var innerHTML = `<p><a href="${blobURL}" class="btn btn-primary" download="${escapeHtml(data.name)}">${i18n.download}</a></p>`;
var pbd = $('#pbd');
pbd.attr('class', 'center-align');
// IE & Edge fix for downloading blob files, gives option to save or open the file when the link is opened.
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
var fileName = escapeHtml(data.name);
window.navigator.msSaveOrOpenBlob(blob, fileName);
} else {
var blobURL = URL.createObjectURL(blob);
}
var innerHTML = `<p><a href="${blobURL}" class="btn btn-primary" download="${escapeHtml(data.name)}">${i18n.download}</a></p>`;
var isZip = ($('#filesize').attr('data-zipped') === 'true');
if (data.type.match(/^image\//) !== null) {
innerHTML += `<img id="render-image" class="responsive-img" alt="${escapeHtml(data.name)}" src="${blobURL}">`;
} else if (data.type.match(/^video\//) !== null) {
innerHTML += `<video class="responsive-video" controls>
var isZip = ($('#filesize').attr('data-zipped') === 'true');
if (data.type.match(/^image\//) !== null) {
innerHTML += `<img id="render-image" class="responsive-img" alt="${escapeHtml(data.name)}" src="${blobURL}">`;
} else if (data.type.match(/^video\//) !== null) {
innerHTML += `<video class="responsive-video" controls>
<source src="${blobURL}" type="${data.type}">
</video>`;
} else if (data.type.match(/^audio\//) !== null) {
innerHTML += `<audio class="responsive-video" controls>
} else if (data.type.match(/^audio\//) !== null) {
innerHTML += `<audio class="responsive-video" controls>
<source src="${blobURL}" type="${data.type}">
</audio>`;
} else if (isZip) {
innerHTML += `<p><a class="btn btn-primary" id="showZipContent">${i18n.showZipContent}</a></p>`;
}
} else if (isZip) {
innerHTML += `<p><a class="btn btn-primary" id="showZipContent">${i18n.showZipContent}</a></p>`;
}
pbd.html(innerHTML);
pbd.html(innerHTML);
if (isZip) {
$('#showZipContent').click(function() {
JSZip.loadAsync(blob)
.then(function (zip) {
var innerHTML = `<h3>${i18n.zipContent}</h3><ul>`;
zip.forEach(function (relativePath, zipEntry) {
innerHTML += `<li>
if (isZip) {
$('#showZipContent').click(function () {
JSZip.loadAsync(blob)
.then(function (zip) {
var innerHTML = `<h3>${i18n.zipContent}</h3><ul>`;
zip.forEach(function (relativePath, zipEntry) {
innerHTML += `<li>
${escapeHtml(zipEntry.name)}
(${filesize(zipEntry._data.uncompressedSize, {base: 10})})
(${filesize(zipEntry._data.uncompressedSize, { base: 10 })})
<a href="#"
download="${escapeHtml(zipEntry.name)}"
class="download-zip-content"
@ -165,47 +165,47 @@ function spawnWebsocket(pa) {
<i class="mdi-file-file-download"></i>
</a>
</li>`
});
innerHTML += '</ul>';
pbd.append(innerHTML);
$('.download-zip-content').click(function(e) {
e.preventDefault();
var t = $(this);
var filename = t.attr('download');
zip.files[filename].async('blob').then(function(blob) {
t.unbind('click');
t.attr('href', URL.createObjectURL(blob));
t[0].click();
});
innerHTML += '</ul>';
pbd.append(innerHTML);
$('.download-zip-content').click(function (e) {
e.preventDefault();
var t = $(this);
var filename = t.attr('download');
zip.files[filename].async('blob').then(function (blob) {
t.unbind('click');
t.attr('href', URL.createObjectURL(blob));
t[0].click();
});
})
$('#showZipContent').hide();
$('#showZipContent').unbind('click');
});
})
$('#showZipContent').hide();
$('#showZipContent').unbind('click');
});
});
}
if ($('#file_pwd').length === 1) {
val = $('#file_pwd').val();
window.ws.send(`{"ended":true, "file_pwd": "${val}"}`);
} else {
window.ws.send('{"ended":true}');
}
window.onbeforeunload = null;
window.completed = true;
$('#abort').remove();
}
if ($('#file_pwd').length === 1) {
val = $('#file_pwd').val();
window.ws.send(`{"ended":true, "file_pwd": "${val}"}`);
} else {
window.ws.send('{"ended":true}');
}
window.onbeforeunload = null;
window.completed = true;
$('#abort').remove();
} else {
var l = $('#loading');
l.html(i18n.loading.replace(/XX1/, (data.part + 1)));
if (ws.readyState === 3) {
window.ws = spawnWebsocket(data.part + 1);
} else {
window.ws.onclose = function() {
window.ws.onclose = function () {
console.log('Connection is closed');
if (!window.completed) {
console.log(`Connection closed. Retrying to get slice ${data.part + 1}`);
window.ws = spawnWebsocket(data.part + 1);
}
}
window.ws.onerror = function() {
window.ws.onerror = function () {
console.log(`Error. Retrying to get slice ${data.part + 1}`);
window.ws = spawnWebsocket(data.part + 1);
};

View File

@ -278,7 +278,7 @@ function uploadFile(i, delay, del_at_first_view) {
lufiApi.lufiCrypto.generateKey().then((random) => {
var randomKey = random;
// Get the file and properties
var file = window.fileList[i];
var name = escapeHtml(file.name);
@ -288,11 +288,11 @@ function uploadFile(i, delay, del_at_first_view) {
parts = 1;
}
// Create a progress bar for the file
var r = $('#ul-results');
var w = $('<li>');
w.addClass('list-group-item');
w.html(`<div class="card">
// Create a progress bar for the file
var r = $('#ul-results');
var w = $('<li>');
w.addClass('list-group-item');
w.html(`<div class="card">
<div>
<a href="#" id="destroy-${window.fc}">
<i class="right mdi-navigation-close small"></i>
@ -300,7 +300,7 @@ function uploadFile(i, delay, del_at_first_view) {
<div class="card-content">
<span class="card-title"
id="name-${window.fc}">${name}</span>
<span id="size-${window.fc }">(${size})</span>
<span id="size-${window.fc}">(${size})</span>
<p id="parts-${window.fc}"></p>
</div>
<div class="progress">
@ -316,14 +316,14 @@ function uploadFile(i, delay, del_at_first_view) {
</div>
</div>
<div>`);
r.prepend(w);
$(`#destroy-${window.fc}`).on('click', function(event) {
event.preventDefault();
window.cancelled.push(i);
destroyBlock(this);
});
r.prepend(w);
$(`#destroy-${window.fc}`).on('click', function (event) {
event.preventDefault();
window.cancelled.push(i);
destroyBlock(this);
});
sliceAndUpload(randomKey, i, parts, 0, delay, del_at_first_view, null, null);
sliceAndUpload(randomKey, i, parts, 0, delay, del_at_first_view, null, null);
}).catch((e) => {
console.error(e);
});
@ -389,30 +389,30 @@ function sliceAndUpload(randomKey, i, parts, j, delay, del_at_first_view, short,
data['file_pwd'] = $('#file_pwd').val();
}
}
data = `${JSON.stringify(data)}XXMOJOXX${JSON.stringify(encrypted)}`;
var percent = Math.round(1000 * j/parts)/10;
var percent = Math.round(1000 * j / parts) / 10;
console.log(`sending slice ${j + 1}/${parts} of file ${file.name} (${percent}%)`);
sl.html(`${percent.toFixed(1)}%`);
// Verify that we have a websocket and send json
if (window.ws.readyState === 3) {
window.ws = spawnWebsocket(0, function() {
window.ws = spawnWebsocket(0, function () {
window.ws.send(data);
});
} else {
window.ws.onclose = function() {
window.ws.onclose = function () {
console.log('Websocket closed, waiting 10sec.');
window.ws = spawnWebsocket(0, function() {
window.ws = spawnWebsocket(0, function () {
console.log(`sending again slice ${j + 1}/${parts} of file ${file.name}`);
window.ws.send(data);
});
};
window.ws.onerror = function() {
window.ws.onerror = function () {
console.log('Error on Websocket, waiting 10sec.');
window.ws = spawnWebsocket(0, function() {
window.ws = spawnWebsocket(0, function () {
console.log(`sending again slice ${j + 1}/${parts} of file ${file.name}`);
window.ws.send(data);
});
@ -469,27 +469,27 @@ function updateProgressBar(data) {
console.log(`getting response for slice ${j + 1}/${parts} of file ${data.name} (${data.duration} sec)`);
var dp = $(`#progress-${window.fc}`);
var key = dp.attr('data-key');
var dp = $(`#progress-${window.fc}`);
var key = dp.attr('data-key');
if (j + 1 === parts) {
window.ws.onclose = function () {
console.log('Connection is closed.');
};
window.ws.onerror = function() {
window.ws.onerror = function () {
console.log('Error on WebSocket connection but file has been fully send, so we dont care.');
}
notify(i18n.fileUploaded, data.name);
$(`#parts-${window.fc}`).remove();
var n = $(`#name-${window.fc}`);
var s = $(`#size-${window.fc}`);
var d = $('<div>');
var url = `${baseURL}r/${short}#${key}`;
var n = $(`#name-${window.fc}`);
var s = $(`#size-${window.fc}`);
var d = $('<div>');
var url = `${baseURL}r/${short}#${key}`;
var del_url = `${actionURL}d/${short}/${data.token}`;
var links = encodeURIComponent(`["${short}"]`);
var limit = (delay === 0) ? i18n.noLimit : `${i18n.expiration} ${formatDate(delay * 86400 + created_at)}`;
var links = encodeURIComponent(`["${short}"]`);
var limit = (delay === 0) ? i18n.noLimit : `${i18n.expiration} ${formatDate(delay * 86400 + created_at)}`;
if (!isGuest) {
n.html(`${n.html()} ${s.html()} <a href="${actionURL}m?links=${links}"><i class="mdi-communication-email"></i></a><br>${limit}`);
d.html(`<div class="card-action">
@ -524,7 +524,7 @@ function updateProgressBar(data) {
p2.remove();
p1.append(d);
$(`#copyurl-${window.fc}`).on('click', function(e) {
$(`#copyurl-${window.fc}`).on('click', function (e) {
e.preventDefault();
copyToClipboard(url);
});
@ -601,9 +601,9 @@ function updateProgressBar(data) {
// Write message instead in a file block
function addAlertOnFile(msg, i, sent_delay, del_at_first_view) {
var n = $(`#name-${window.fc}`);
var p = $(`#progress-${window.fc}`);
var d = $('<div>');
var n = $(`#name-${window.fc}`);
var p = $(`#progress-${window.fc}`);
var d = $('<div>');
p.parent().remove();
d.addClass('card pink');