Formatting
This commit is contained in:
parent
d071467ea7
commit
3ab54f6dae
|
@ -17,19 +17,19 @@ function pageKey() {
|
||||||
// First, strip everything after the equal sign (=) which signals end of base64 string.
|
// First, strip everything after the equal sign (=) which signals end of base64 string.
|
||||||
i = key.indexOf('=');
|
i = key.indexOf('=');
|
||||||
let isb64 = false
|
let isb64 = false
|
||||||
|
|
||||||
if (i>-1) {
|
if (i > -1) {
|
||||||
key = key.substring(0, i + 1);
|
key = key.substring(0, i + 1);
|
||||||
|
|
||||||
isb64 = true
|
isb64 = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the equal sign was not present, some parameters may remain:
|
// 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
|
// Then add trailing equal sign if it's missing and was using the Sjcl algorithm
|
||||||
if (isb64) {
|
if (isb64) {
|
||||||
if (key.charAt(key.length-1)!=='=') key += '=';
|
if (key.charAt(key.length - 1) !== '=') key += '=';
|
||||||
}
|
}
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
|
@ -95,16 +95,16 @@ function spawnWebsocket(pa) {
|
||||||
window.attempts = 10;
|
window.attempts = 10;
|
||||||
} else {
|
} else {
|
||||||
console.log(`Getting slice ${data.part + 1} of ${data.total}`);
|
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 file was used using Lufi API
|
||||||
if (slice.iv) {
|
if (slice.iv) {
|
||||||
slice.iv = new Uint8Array(Object.values(slice.iv))
|
slice.iv = new Uint8Array(Object.values(slice.iv))
|
||||||
}
|
}
|
||||||
|
|
||||||
var percent = Math.round(1000 * (data.part + 1)/data.total)/10;
|
var percent = Math.round(1000 * (data.part + 1) / data.total) / 10;
|
||||||
var wClass = percent.toString().replace('.', '-');
|
var wClass = percent.toString().replace('.', '-');
|
||||||
var pb = $('#pb');
|
var pb = $('#pb');
|
||||||
pb.removeClass();
|
pb.removeClass();
|
||||||
pb.addClass('determinate');
|
pb.addClass('determinate');
|
||||||
pb.addClass(`width-${wClass}`);
|
pb.addClass(`width-${wClass}`);
|
||||||
|
@ -112,7 +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) => {
|
||||||
window.a[data.part] = decrypted;
|
window.a[data.part] = decrypted;
|
||||||
|
|
||||||
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 });
|
||||||
|
@ -121,43 +121,43 @@ function spawnWebsocket(pa) {
|
||||||
$('#please-wait').remove();
|
$('#please-wait').remove();
|
||||||
$('#loading').remove();
|
$('#loading').remove();
|
||||||
|
|
||||||
var pbd = $('#pbd');
|
var pbd = $('#pbd');
|
||||||
pbd.attr('class', 'center-align');
|
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.
|
// 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) {
|
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
|
||||||
var fileName = escapeHtml(data.name);
|
var fileName = escapeHtml(data.name);
|
||||||
window.navigator.msSaveOrOpenBlob(blob, fileName);
|
window.navigator.msSaveOrOpenBlob(blob, fileName);
|
||||||
} else {
|
} else {
|
||||||
var blobURL = URL.createObjectURL(blob);
|
var blobURL = URL.createObjectURL(blob);
|
||||||
}
|
}
|
||||||
var innerHTML = `<p><a href="${blobURL}" class="btn btn-primary" download="${escapeHtml(data.name)}">${i18n.download}</a></p>`;
|
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');
|
var isZip = ($('#filesize').attr('data-zipped') === 'true');
|
||||||
if (data.type.match(/^image\//) !== null) {
|
if (data.type.match(/^image\//) !== null) {
|
||||||
innerHTML += `<img id="render-image" class="responsive-img" alt="${escapeHtml(data.name)}" src="${blobURL}">`;
|
innerHTML += `<img id="render-image" class="responsive-img" alt="${escapeHtml(data.name)}" src="${blobURL}">`;
|
||||||
} else if (data.type.match(/^video\//) !== null) {
|
} else if (data.type.match(/^video\//) !== null) {
|
||||||
innerHTML += `<video class="responsive-video" controls>
|
innerHTML += `<video class="responsive-video" controls>
|
||||||
<source src="${blobURL}" type="${data.type}">
|
<source src="${blobURL}" type="${data.type}">
|
||||||
</video>`;
|
</video>`;
|
||||||
} else if (data.type.match(/^audio\//) !== null) {
|
} else if (data.type.match(/^audio\//) !== null) {
|
||||||
innerHTML += `<audio class="responsive-video" controls>
|
innerHTML += `<audio class="responsive-video" controls>
|
||||||
<source src="${blobURL}" type="${data.type}">
|
<source src="${blobURL}" type="${data.type}">
|
||||||
</audio>`;
|
</audio>`;
|
||||||
} else if (isZip) {
|
} else if (isZip) {
|
||||||
innerHTML += `<p><a class="btn btn-primary" id="showZipContent">${i18n.showZipContent}</a></p>`;
|
innerHTML += `<p><a class="btn btn-primary" id="showZipContent">${i18n.showZipContent}</a></p>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
pbd.html(innerHTML);
|
pbd.html(innerHTML);
|
||||||
|
|
||||||
if (isZip) {
|
if (isZip) {
|
||||||
$('#showZipContent').click(function() {
|
$('#showZipContent').click(function () {
|
||||||
JSZip.loadAsync(blob)
|
JSZip.loadAsync(blob)
|
||||||
.then(function (zip) {
|
.then(function (zip) {
|
||||||
var innerHTML = `<h3>${i18n.zipContent}</h3><ul>`;
|
var innerHTML = `<h3>${i18n.zipContent}</h3><ul>`;
|
||||||
zip.forEach(function (relativePath, zipEntry) {
|
zip.forEach(function (relativePath, zipEntry) {
|
||||||
innerHTML += `<li>
|
innerHTML += `<li>
|
||||||
${escapeHtml(zipEntry.name)}
|
${escapeHtml(zipEntry.name)}
|
||||||
(${filesize(zipEntry._data.uncompressedSize, {base: 10})})
|
(${filesize(zipEntry._data.uncompressedSize, { base: 10 })})
|
||||||
<a href="#"
|
<a href="#"
|
||||||
download="${escapeHtml(zipEntry.name)}"
|
download="${escapeHtml(zipEntry.name)}"
|
||||||
class="download-zip-content"
|
class="download-zip-content"
|
||||||
|
@ -165,47 +165,47 @@ function spawnWebsocket(pa) {
|
||||||
<i class="mdi-file-file-download"></i>
|
<i class="mdi-file-file-download"></i>
|
||||||
</a>
|
</a>
|
||||||
</li>`
|
</li>`
|
||||||
});
|
});
|
||||||
innerHTML += '</ul>';
|
innerHTML += '</ul>';
|
||||||
pbd.append(innerHTML);
|
pbd.append(innerHTML);
|
||||||
$('.download-zip-content').click(function(e) {
|
$('.download-zip-content').click(function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var t = $(this);
|
var t = $(this);
|
||||||
var filename = t.attr('download');
|
var filename = t.attr('download');
|
||||||
zip.files[filename].async('blob').then(function(blob) {
|
zip.files[filename].async('blob').then(function (blob) {
|
||||||
t.unbind('click');
|
t.unbind('click');
|
||||||
t.attr('href', URL.createObjectURL(blob));
|
t.attr('href', URL.createObjectURL(blob));
|
||||||
t[0].click();
|
t[0].click();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
$('#showZipContent').hide();
|
||||||
|
$('#showZipContent').unbind('click');
|
||||||
});
|
});
|
||||||
})
|
|
||||||
$('#showZipContent').hide();
|
|
||||||
$('#showZipContent').unbind('click');
|
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
if ($('#file_pwd').length === 1) {
|
||||||
if ($('#file_pwd').length === 1) {
|
val = $('#file_pwd').val();
|
||||||
val = $('#file_pwd').val();
|
window.ws.send(`{"ended":true, "file_pwd": "${val}"}`);
|
||||||
window.ws.send(`{"ended":true, "file_pwd": "${val}"}`);
|
} else {
|
||||||
} else {
|
window.ws.send('{"ended":true}');
|
||||||
window.ws.send('{"ended":true}');
|
}
|
||||||
}
|
window.onbeforeunload = null;
|
||||||
window.onbeforeunload = null;
|
window.completed = true;
|
||||||
window.completed = true;
|
$('#abort').remove();
|
||||||
$('#abort').remove();
|
|
||||||
} else {
|
} else {
|
||||||
var l = $('#loading');
|
var l = $('#loading');
|
||||||
l.html(i18n.loading.replace(/XX1/, (data.part + 1)));
|
l.html(i18n.loading.replace(/XX1/, (data.part + 1)));
|
||||||
if (ws.readyState === 3) {
|
if (ws.readyState === 3) {
|
||||||
window.ws = spawnWebsocket(data.part + 1);
|
window.ws = spawnWebsocket(data.part + 1);
|
||||||
} else {
|
} else {
|
||||||
window.ws.onclose = function() {
|
window.ws.onclose = function () {
|
||||||
console.log('Connection is closed');
|
console.log('Connection is closed');
|
||||||
if (!window.completed) {
|
if (!window.completed) {
|
||||||
console.log(`Connection closed. Retrying to get slice ${data.part + 1}`);
|
console.log(`Connection closed. Retrying to get slice ${data.part + 1}`);
|
||||||
window.ws = spawnWebsocket(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}`);
|
console.log(`Error. Retrying to get slice ${data.part + 1}`);
|
||||||
window.ws = spawnWebsocket(data.part + 1);
|
window.ws = spawnWebsocket(data.part + 1);
|
||||||
};
|
};
|
||||||
|
|
|
@ -278,7 +278,7 @@ function uploadFile(i, delay, del_at_first_view) {
|
||||||
|
|
||||||
lufiApi.lufiCrypto.generateKey().then((random) => {
|
lufiApi.lufiCrypto.generateKey().then((random) => {
|
||||||
var randomKey = random;
|
var randomKey = random;
|
||||||
|
|
||||||
// Get the file and properties
|
// Get the file and properties
|
||||||
var file = window.fileList[i];
|
var file = window.fileList[i];
|
||||||
var name = escapeHtml(file.name);
|
var name = escapeHtml(file.name);
|
||||||
|
@ -288,11 +288,11 @@ function uploadFile(i, delay, del_at_first_view) {
|
||||||
parts = 1;
|
parts = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a progress bar for the file
|
// Create a progress bar for the file
|
||||||
var r = $('#ul-results');
|
var r = $('#ul-results');
|
||||||
var w = $('<li>');
|
var w = $('<li>');
|
||||||
w.addClass('list-group-item');
|
w.addClass('list-group-item');
|
||||||
w.html(`<div class="card">
|
w.html(`<div class="card">
|
||||||
<div>
|
<div>
|
||||||
<a href="#" id="destroy-${window.fc}">
|
<a href="#" id="destroy-${window.fc}">
|
||||||
<i class="right mdi-navigation-close small"></i>
|
<i class="right mdi-navigation-close small"></i>
|
||||||
|
@ -300,7 +300,7 @@ function uploadFile(i, delay, del_at_first_view) {
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
<span class="card-title"
|
<span class="card-title"
|
||||||
id="name-${window.fc}">${name}</span>
|
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>
|
<p id="parts-${window.fc}"></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="progress">
|
<div class="progress">
|
||||||
|
@ -316,14 +316,14 @@ function uploadFile(i, delay, del_at_first_view) {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>`);
|
<div>`);
|
||||||
r.prepend(w);
|
r.prepend(w);
|
||||||
$(`#destroy-${window.fc}`).on('click', function(event) {
|
$(`#destroy-${window.fc}`).on('click', function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
window.cancelled.push(i);
|
window.cancelled.push(i);
|
||||||
destroyBlock(this);
|
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) => {
|
}).catch((e) => {
|
||||||
console.error(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['file_pwd'] = $('#file_pwd').val();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data = `${JSON.stringify(data)}XXMOJOXX${JSON.stringify(encrypted)}`;
|
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}%)`);
|
console.log(`sending slice ${j + 1}/${parts} of file ${file.name} (${percent}%)`);
|
||||||
|
|
||||||
sl.html(`${percent.toFixed(1)}%`);
|
sl.html(`${percent.toFixed(1)}%`);
|
||||||
|
|
||||||
// Verify that we have a websocket and send json
|
// Verify that we have a websocket and send json
|
||||||
if (window.ws.readyState === 3) {
|
if (window.ws.readyState === 3) {
|
||||||
window.ws = spawnWebsocket(0, function() {
|
window.ws = spawnWebsocket(0, function () {
|
||||||
window.ws.send(data);
|
window.ws.send(data);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
window.ws.onclose = function() {
|
window.ws.onclose = function () {
|
||||||
console.log('Websocket closed, waiting 10sec.');
|
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}`);
|
console.log(`sending again slice ${j + 1}/${parts} of file ${file.name}`);
|
||||||
window.ws.send(data);
|
window.ws.send(data);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
window.ws.onerror = function() {
|
window.ws.onerror = function () {
|
||||||
console.log('Error on Websocket, waiting 10sec.');
|
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}`);
|
console.log(`sending again slice ${j + 1}/${parts} of file ${file.name}`);
|
||||||
window.ws.send(data);
|
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)`);
|
console.log(`getting response for slice ${j + 1}/${parts} of file ${data.name} (${data.duration} sec)`);
|
||||||
|
|
||||||
var dp = $(`#progress-${window.fc}`);
|
var dp = $(`#progress-${window.fc}`);
|
||||||
var key = dp.attr('data-key');
|
var key = dp.attr('data-key');
|
||||||
|
|
||||||
if (j + 1 === parts) {
|
if (j + 1 === parts) {
|
||||||
window.ws.onclose = function () {
|
window.ws.onclose = function () {
|
||||||
console.log('Connection is closed.');
|
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 don’t care.');
|
console.log('Error on WebSocket connection but file has been fully send, so we don’t care.');
|
||||||
}
|
}
|
||||||
|
|
||||||
notify(i18n.fileUploaded, data.name);
|
notify(i18n.fileUploaded, data.name);
|
||||||
|
|
||||||
$(`#parts-${window.fc}`).remove();
|
$(`#parts-${window.fc}`).remove();
|
||||||
var n = $(`#name-${window.fc}`);
|
var n = $(`#name-${window.fc}`);
|
||||||
var s = $(`#size-${window.fc}`);
|
var s = $(`#size-${window.fc}`);
|
||||||
var d = $('<div>');
|
var d = $('<div>');
|
||||||
var url = `${baseURL}r/${short}#${key}`;
|
var url = `${baseURL}r/${short}#${key}`;
|
||||||
var del_url = `${actionURL}d/${short}/${data.token}`;
|
var del_url = `${actionURL}d/${short}/${data.token}`;
|
||||||
var links = encodeURIComponent(`["${short}"]`);
|
var links = encodeURIComponent(`["${short}"]`);
|
||||||
var limit = (delay === 0) ? i18n.noLimit : `${i18n.expiration} ${formatDate(delay * 86400 + created_at)}`;
|
var limit = (delay === 0) ? i18n.noLimit : `${i18n.expiration} ${formatDate(delay * 86400 + created_at)}`;
|
||||||
if (!isGuest) {
|
if (!isGuest) {
|
||||||
n.html(`${n.html()} ${s.html()} <a href="${actionURL}m?links=${links}"><i class="mdi-communication-email"></i></a><br>${limit}`);
|
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">
|
d.html(`<div class="card-action">
|
||||||
|
@ -524,7 +524,7 @@ function updateProgressBar(data) {
|
||||||
p2.remove();
|
p2.remove();
|
||||||
p1.append(d);
|
p1.append(d);
|
||||||
|
|
||||||
$(`#copyurl-${window.fc}`).on('click', function(e) {
|
$(`#copyurl-${window.fc}`).on('click', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
copyToClipboard(url);
|
copyToClipboard(url);
|
||||||
});
|
});
|
||||||
|
@ -601,9 +601,9 @@ function updateProgressBar(data) {
|
||||||
|
|
||||||
// Write message instead in a file block
|
// Write message instead in a file block
|
||||||
function addAlertOnFile(msg, i, sent_delay, del_at_first_view) {
|
function addAlertOnFile(msg, i, sent_delay, del_at_first_view) {
|
||||||
var n = $(`#name-${window.fc}`);
|
var n = $(`#name-${window.fc}`);
|
||||||
var p = $(`#progress-${window.fc}`);
|
var p = $(`#progress-${window.fc}`);
|
||||||
var d = $('<div>');
|
var d = $('<div>');
|
||||||
|
|
||||||
p.parent().remove();
|
p.parent().remove();
|
||||||
d.addClass('card pink');
|
d.addClass('card pink');
|
||||||
|
|
Loading…
Reference in New Issue