🎨 — Use template literals in js
This commit is contained in:
parent
43ee9fc4da
commit
cd4168d2b8
|
@ -3,6 +3,7 @@ Revision history for Lufi
|
|||
0.07.0 ????-??-??
|
||||
- ⬆️ — Update jQuery
|
||||
- 🩹 — Fix a format query parameter
|
||||
- 🎨 — Use template literals in js
|
||||
|
||||
0.06.00 2023-12-18
|
||||
- ⬆️ — Update deps
|
||||
|
|
|
@ -11,13 +11,13 @@ function pageKey() {
|
|||
// We will strip any additional data.
|
||||
|
||||
// First, strip everything after the equal sign (=) which signals end of base64 string.
|
||||
i = key.indexOf('='); if (i>-1) { key = key.substring(0,i+1); }
|
||||
i = key.indexOf('='); if (i>-1) { key = key.substring(0, i + 1); }
|
||||
|
||||
// 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
|
||||
if (key.charAt(key.length-1)!=='=') key+='=';
|
||||
if (key.charAt(key.length-1)!=='=') key += '=';
|
||||
|
||||
return key;
|
||||
}
|
||||
|
@ -38,11 +38,11 @@ function addAlert(msg) {
|
|||
var pbd = $('.file-progress');
|
||||
pbd.attr('role', 'alert');
|
||||
pbd.removeClass('progress');
|
||||
pbd.html(['<div class="card pink">',
|
||||
'<div class="card-content white-text">',
|
||||
'<strong>', msg, '</strong>',
|
||||
'</div>',
|
||||
'</div>'].join(''));
|
||||
pbd.html(`<div class="card pink">
|
||||
<div class="card-content white-text">
|
||||
<strong>${msg}</strong>
|
||||
</div>
|
||||
</div>`);
|
||||
}
|
||||
|
||||
// Spawn WebSocket
|
||||
|
@ -55,9 +55,10 @@ function spawnWebsocket(pa) {
|
|||
var l = $('#loading');
|
||||
l.html(i18n.loading.replace(/XX1/, (pa + 1)));
|
||||
if ($('#file_pwd').length === 1) {
|
||||
window.ws.send('{"part":'+pa+', "file_pwd": "'+$('#file_pwd').val()+'"}');
|
||||
val = $('#file_pwd').val();
|
||||
window.ws.send(`{"part":${pa}, "file_pwd": "${val}"}`);
|
||||
} else {
|
||||
window.ws.send('{"part":'+pa+'}');
|
||||
window.ws.send(`{"part":${pa}}`);
|
||||
}
|
||||
};
|
||||
ws.onclose = function() {
|
||||
|
@ -65,7 +66,7 @@ function spawnWebsocket(pa) {
|
|||
if (!window.completed) {
|
||||
window.attempts++;
|
||||
if (window.attempts < 10) {
|
||||
console.log('Connection closed. Retrying to get slice '+pa);
|
||||
console.log(`Connection closed. Retrying to get slice ${pa}`);
|
||||
window.ws = spawnWebsocket(pa);
|
||||
} else {
|
||||
alert(i18n.tooMuchAttempts);
|
||||
|
@ -89,16 +90,16 @@ function spawnWebsocket(pa) {
|
|||
window.onbeforeunload = null;
|
||||
window.attempts = 10;
|
||||
} 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 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);
|
||||
pb.addClass(`width-${wClass}`);
|
||||
pb.attr('aria-valuenow', percent);
|
||||
$('#pbt').html(percent+'%');
|
||||
$('#pbt').html(`${percent}%`);
|
||||
try {
|
||||
var b64 = sjcl.decrypt(window.key, slice);
|
||||
window.a[data.part] = base64ToArrayBuffer(b64);
|
||||
|
@ -118,43 +119,44 @@ function spawnWebsocket(pa) {
|
|||
} 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 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.push('<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) {
|
||||
innerHTML.push('<video class="responsive-video" controls>',
|
||||
'<source src="', blobURL, '" type="', data.type, '">',
|
||||
'</video>');
|
||||
innerHTML += `<video class="responsive-video" controls>
|
||||
<source src="${blobURL}" type="${data.type}">
|
||||
</video>`;
|
||||
} else if (data.type.match(/^audio\//) !== null) {
|
||||
innerHTML.push('<audio class="responsive-video" controls>',
|
||||
'<source src="', blobURL, '" type="', data.type, '">',
|
||||
'</audio>');
|
||||
innerHTML += `<audio class="responsive-video" controls>
|
||||
<source src="${blobURL}" type="${data.type}">
|
||||
</audio>`;
|
||||
} else if (isZip) {
|
||||
innerHTML.push('<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.join(''));
|
||||
pbd.html(innerHTML);
|
||||
|
||||
if (isZip) {
|
||||
$('#showZipContent').click(function() {
|
||||
JSZip.loadAsync(blob)
|
||||
.then(function (zip) {
|
||||
var innerHTML = ['<h3>', i18n.zipContent, '</h3><ul>'];
|
||||
var innerHTML = `<h3>${i18n.zipContent}</h3><ul>`;
|
||||
zip.forEach(function (relativePath, zipEntry) {
|
||||
innerHTML.push(
|
||||
'<li>',
|
||||
escapeHtml(zipEntry.name),
|
||||
' (', filesize(zipEntry._data.uncompressedSize, {base: 10}), ') ',
|
||||
'<a href="#" download="', escapeHtml(zipEntry.name), '" class="download-zip-content" title="', i18n.download, '">',
|
||||
'<i class="mdi-file-file-download"></i>',
|
||||
'</a>',
|
||||
'</li>'
|
||||
);
|
||||
innerHTML += `<li>
|
||||
${escapeHtml(zipEntry.name)}
|
||||
(${filesize(zipEntry._data.uncompressedSize, {base: 10})})
|
||||
<a href="#"
|
||||
download="${escapeHtml(zipEntry.name)}"
|
||||
class="download-zip-content"
|
||||
title="${i18n.download}">
|
||||
<i class="mdi-file-file-download"></i>
|
||||
</a>
|
||||
</li>`
|
||||
});
|
||||
innerHTML.push('</ul>');
|
||||
pbd.append(innerHTML.join(''));
|
||||
innerHTML += '</ul>';
|
||||
pbd.append(innerHTML);
|
||||
$('.download-zip-content').click(function(e) {
|
||||
e.preventDefault();
|
||||
var t = $(this);
|
||||
|
@ -171,7 +173,8 @@ function spawnWebsocket(pa) {
|
|||
});
|
||||
}
|
||||
if ($('#file_pwd').length === 1) {
|
||||
window.ws.send('{"ended":true, "file_pwd": "'+$('#file_pwd').val()+'"}');
|
||||
val = $('#file_pwd').val();
|
||||
window.ws.send(`{"ended":true, "file_pwd": "${val}"}`);
|
||||
} else {
|
||||
window.ws.send('{"ended":true}');
|
||||
}
|
||||
|
@ -187,18 +190,19 @@ function spawnWebsocket(pa) {
|
|||
window.ws.onclose = function() {
|
||||
console.log('Connection is closed');
|
||||
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.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);
|
||||
};
|
||||
if ($('#file_pwd').length === 1) {
|
||||
window.ws.send('{"part":'+(data.part + 1)+', "file_pwd": "'+$('#file_pwd').val()+'"}');
|
||||
val = $('#file_pwd').val();
|
||||
window.ws.send(`{"part":${data.part + 1}, "file_pwd": "${val}"}`);
|
||||
} else {
|
||||
window.ws.send('{"part":'+(data.part + 1)+'}');
|
||||
window.ws.send(`{"part":${data.part + 1}}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -215,7 +219,7 @@ function spawnWebsocket(pa) {
|
|||
ws.onerror = function() {
|
||||
window.attempts++;
|
||||
if (window.attempts < 10) {
|
||||
console.log('Error. Retrying to get slice '+pa);
|
||||
console.log(`Error. Retrying to get slice ${pa}`);
|
||||
window.ws = spawnWebsocket(pa);
|
||||
} else {
|
||||
alert(i18n.tooMuchAttempts);
|
||||
|
@ -229,7 +233,13 @@ $(document).ready(function(){
|
|||
window.ws.onclose = function() {};
|
||||
window.ws.close();
|
||||
$('#please-wait, #loading, #pbd, #abort').remove();
|
||||
$('#filesize').parent().append('<h4>'+i18n.aborted1+'</h4><a id="reloadLocation" class="waves-effect waves-light btn">'+i18n.aborted2+'</a></p>');
|
||||
$('#filesize').parent().append(`<h4>${i18n.aborted1}</h4>
|
||||
<p>
|
||||
<a id="reloadLocation"
|
||||
class="waves-effect waves-light btn">
|
||||
${i18n.aborted2}
|
||||
</a>
|
||||
</p>`);
|
||||
window.onbeforeunload = null;
|
||||
$('#reloadLocation').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
// vim:set sw=4 ts=4 sts=4 ft=javascript expandtab:
|
||||
// Add item to localStorage
|
||||
function addItem(item) {
|
||||
var files = localStorage.getItem(window.prefix + 'files');
|
||||
var files = localStorage.getItem(`${window.prefix}files`);
|
||||
if (files === null) {
|
||||
files = new Array();
|
||||
} else {
|
||||
files = JSON.parse(files);
|
||||
}
|
||||
files.push(item);
|
||||
localStorage.setItem(window.prefix + 'files', JSON.stringify(files));
|
||||
localStorage.setItem(`${window.prefix}files`, JSON.stringify(files));
|
||||
}
|
||||
|
||||
function delItem(name) {
|
||||
var files = localStorage.getItem(window.prefix + 'files');
|
||||
var files = localStorage.getItem(`${window.prefix}files`);
|
||||
if (files === null) {
|
||||
files = new Array();
|
||||
} else {
|
||||
|
@ -24,11 +24,11 @@ function delItem(name) {
|
|||
files.splice(i, 1);
|
||||
}
|
||||
}
|
||||
localStorage.setItem(window.prefix + 'files', JSON.stringify(files));
|
||||
localStorage.setItem(`${window.prefix}files`, JSON.stringify(files));
|
||||
}
|
||||
|
||||
function itemExists(name) {
|
||||
var files = localStorage.getItem(window.prefix + 'files');
|
||||
var files = localStorage.getItem(`${window.prefix}files`);
|
||||
if (files === null) {
|
||||
return false;
|
||||
} else {
|
||||
|
@ -59,7 +59,7 @@ function invertSelection(event) {
|
|||
|
||||
function purgeExpired(event) {
|
||||
event.preventDefault();
|
||||
var files = JSON.parse(localStorage.getItem(window.prefix + 'files'));
|
||||
var files = JSON.parse(localStorage.getItem(`${window.prefix}files`));
|
||||
|
||||
files.forEach(function(element, index, array) {
|
||||
$.ajax({
|
||||
|
@ -73,7 +73,7 @@ function purgeExpired(event) {
|
|||
success: function(data, textStatus, jqXHR) {
|
||||
if (data.success) {
|
||||
if (data.deleted) {
|
||||
$('#count-'+data.short).parent().remove();
|
||||
$(`#count-${data.short}`).parent().remove();
|
||||
delItem(data.short);
|
||||
}
|
||||
}
|
||||
|
@ -84,11 +84,11 @@ function purgeExpired(event) {
|
|||
|
||||
function exportStorage(event) {
|
||||
event.preventDefault();
|
||||
var a = $('<a id="data-json">');
|
||||
var a = $('<a id="data-json">');
|
||||
a.hide();
|
||||
$('body').append(a);
|
||||
|
||||
var storageData = [localStorage.getItem(window.prefix + 'files')];
|
||||
var storageData = [localStorage.getItem(`${window.prefix}files`)];
|
||||
var exportFile = new Blob(storageData, {type : 'application/json'});
|
||||
var url = window.URL.createObjectURL(exportFile);
|
||||
|
||||
|
@ -146,7 +146,7 @@ function delFile() {
|
|||
},
|
||||
success: function(data) {
|
||||
if (data.success) {
|
||||
$('#row-'+short).remove();
|
||||
$(`#row-${short}`).remove();
|
||||
delItem(short);
|
||||
} else {
|
||||
alert(data.msg);
|
||||
|
@ -178,15 +178,15 @@ function massDelete(event) {
|
|||
function populateFilesTable() {
|
||||
$('#myfiles').empty();
|
||||
|
||||
var files = localStorage.getItem(window.prefix + 'files');
|
||||
var files = localStorage.getItem(`${window.prefix}files`);
|
||||
if (files === null) {
|
||||
var filesWithoutPrefix = localStorage.getItem('files');
|
||||
if (filesWithoutPrefix !== null) {
|
||||
if (window.confirm(i18n.importFilesWithoutPrefix)) {
|
||||
localStorage.setItem(window.prefix + 'files', filesWithoutPrefix);
|
||||
localStorage.setItem(`${window.prefix}files`, filesWithoutPrefix);
|
||||
files = JSON.parse(filesWithoutPrefix);
|
||||
} else {
|
||||
localStorage.setItem(window.prefix + 'files', JSON.stringify([]));
|
||||
localStorage.setItem(`${window.prefix}files`, JSON.stringify([]));
|
||||
files = new Array();
|
||||
}
|
||||
} else {
|
||||
|
@ -206,45 +206,59 @@ function populateFilesTable() {
|
|||
});
|
||||
files.forEach(function(element, index, array) {
|
||||
var del_view = (element.del_at_first_view) ? '<i class="small mdi-action-done"></i>' : '<i class="small mdi-navigation-close"></i>';
|
||||
var dlink = actionURL+'d/'+element.short+'/'+element.token;
|
||||
var dlink = `${actionURL}d/${element.short}/${element.token}`;
|
||||
var limit = (element.delay === 0) ? i18n.noExpiration : moment.unix(element.delay * 86400 + element.created_at).locale(window.navigator.language).format('LLLL');
|
||||
var created_at = moment.unix(element.created_at).locale(window.navigator.language).format('LLLL');
|
||||
|
||||
var tr = $('<tr id="row-'+element.short+'">');
|
||||
tr.html([ '<td class="center-align">',
|
||||
'<input type="checkbox" id="check-', element.short,'" data-short="', element.short, '" data-dlink="', dlink, '" data-checked="">',
|
||||
'<label for="check-', element.short,'"></label>',
|
||||
'</td>',
|
||||
'<td class="left-align">',
|
||||
escapeHtml(element.name),
|
||||
'</td>',
|
||||
'<td class="center-align">',
|
||||
'<a href="', element.url, '" class="classic"><i class="small mdi-file-file-download"></i></a>',
|
||||
'</td>',
|
||||
'<td id="count-', element.short, '" class="center-align">',
|
||||
'</td>',
|
||||
'<td class="center-align">',
|
||||
del_view,
|
||||
'</td>',
|
||||
'<td>',
|
||||
created_at,
|
||||
'</td>',
|
||||
'<td>',
|
||||
limit,
|
||||
'</td>',
|
||||
'<td class="center-align">',
|
||||
'<a id="del-', element.short, '" data-short="', element.short, '" data-dlink="', dlink, '" href="#" class="classic"><i class="small mdi-action-delete"></i></a>',
|
||||
'</td>',
|
||||
'<td class="center-align">',
|
||||
'<a href="'+actionURL+'m?links=["'+element.short+'"]" class="classic"><i class="small mdi-communication-email"></i></a>',
|
||||
'</td>'].join(''));
|
||||
var tr = $(`<tr id="row-${element.short}">`);
|
||||
tr.html(`<td class="center-align">
|
||||
<input type="checkbox"
|
||||
id="check-${element.short}"
|
||||
data-short="${element.short}"
|
||||
data-dlink="${dlink}"
|
||||
data-checked="">
|
||||
<label for="check-${element.short}"></label>
|
||||
</td>
|
||||
<td class="left-align">
|
||||
${escapeHtml(element.name)}
|
||||
</td>
|
||||
<td class="center-align">
|
||||
<a href="${element.url}"
|
||||
class="classic">
|
||||
<i class="small mdi-file-file-download"></i>
|
||||
</a>
|
||||
</td>
|
||||
<td id="count-${element.short}" class="center-align">
|
||||
</td>
|
||||
<td class="center-align">
|
||||
${del_view}
|
||||
</td>
|
||||
<td>
|
||||
${created_at}
|
||||
</td>
|
||||
<td>
|
||||
${limit}
|
||||
</td>
|
||||
<td class="center-align">
|
||||
<a id="del-${element.short}"
|
||||
data-short="${element.short}"
|
||||
data-dlink="${dlink}"
|
||||
href="#"
|
||||
class="classic">
|
||||
<i class="small mdi-action-delete"></i>
|
||||
</a>
|
||||
</td>
|
||||
<td class="center-align">
|
||||
<a href="${actionURL}m?links=["${element.short}"]"
|
||||
class="classic"><i class="small mdi-communication-email"></i></a>
|
||||
</td>`);
|
||||
$('#myfiles').append(tr);
|
||||
$('#del-'+element.short).on('click', delFile);
|
||||
$('label[for="check-'+element.short+'"]').on('click', function(){
|
||||
if ($('#check-'+element.short).attr('data-checked') && $('#check-'+element.short).attr('data-checked') === 'data-checked') {
|
||||
$('#check-'+element.short).attr('data-checked', null);
|
||||
$(`#del-${element.short}`).on('click', delFile);
|
||||
$(`label[for="check-${element.short}"]`).on('click', function(){
|
||||
if ($(`#check-${element.short}`).attr('data-checked') && $(`#check-${element.short}`).attr('data-checked') === 'data-checked') {
|
||||
$(`#check-${element.short}`).attr('data-checked', null);
|
||||
} else {
|
||||
$('#check-'+element.short).attr('data-checked', 'data-checked');
|
||||
$(`#check-${element.short}`).attr('data-checked', 'data-checked');
|
||||
}
|
||||
evaluateMassDelete();
|
||||
});
|
||||
|
@ -259,13 +273,13 @@ function populateFilesTable() {
|
|||
},
|
||||
success: function(data, textStatus, jqXHR) {
|
||||
if (data.success) {
|
||||
$('#count-'+data.short).html(data.counter);
|
||||
$(`#count-${data.short}`).html(data.counter);
|
||||
if (data.deleted) {
|
||||
$('#count-'+data.short).parent().addClass('purple lighten-4');
|
||||
$(`#count-${data.short}`).parent().addClass('purple lighten-4');
|
||||
}
|
||||
} else {
|
||||
alert(data.msg);
|
||||
$('#count-'+data.short).parent().remove();
|
||||
$(`#count-${data.short}`).parent().remove();
|
||||
if (data.missing) {
|
||||
delItem(data.short);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ function deleteInvit(e) {
|
|||
if (data.success) {
|
||||
data.tokens.forEach(function(t) {
|
||||
Materialize.toast(t.msg, 6000, 'teal accent-3');
|
||||
$('#row-' + t.token).remove();
|
||||
$(`#row-${t.token}`).remove();
|
||||
});
|
||||
data.failures.forEach(function(msg) {
|
||||
Materialize.toast(msg, 10000, 'red accent-2');
|
||||
|
@ -74,8 +74,8 @@ function resendMail(e) {
|
|||
success: function(data, textStatus, jqXHR) {
|
||||
data.success.forEach(function(s) {
|
||||
Materialize.toast(s.msg, 6000, 'teal accent-3');
|
||||
$('#expire-' + s.token).text(s.expires)
|
||||
$('#' + s.token).click();
|
||||
$(`#expire-${s.token}`).text(s.expires)
|
||||
$(`#${s.token}`).click();
|
||||
});
|
||||
data.failures.forEach(function(msg) {
|
||||
Materialize.toast(msg, 10000, 'red accent-2');
|
||||
|
@ -97,19 +97,19 @@ function toggleVisibility(e) {
|
|||
success: function(data, textStatus, jqXHR) {
|
||||
if (data.success) {
|
||||
data.tokens.forEach(function(t) {
|
||||
var row = $('#row-' + t.token)
|
||||
var row = $(`#row-${t.token}`)
|
||||
if (t.show) {
|
||||
row.attr('data-visibility', 1);
|
||||
row.removeClass('hide');
|
||||
$('#row-' + t.token + ' > td:first i').remove();
|
||||
$(`#row-${t.token} > td:first i`).remove();
|
||||
} else {
|
||||
row.attr('data-visibility', 0);
|
||||
if ($('#myInvitations').attr('data-visibility') === 'hidden') {
|
||||
row.addClass('hide');
|
||||
}
|
||||
$('#row-' + t.token + ' > td:first').append(i18n.hiddenMark);
|
||||
$(`#row-${t.token} > td:first`).append(i18n.hiddenMark);
|
||||
}
|
||||
$('#' + t.token).click();
|
||||
$(`#${t.token}`).click();
|
||||
});
|
||||
disableButtons();
|
||||
} else {
|
||||
|
@ -169,25 +169,17 @@ function fillModal() {
|
|||
);
|
||||
|
||||
var files = JSON.parse(el.attr('data-files'));
|
||||
var content = [];
|
||||
var content = '';
|
||||
for (i = 0; i < files.length; i++) {
|
||||
var f = files[i];
|
||||
var expires = i18n.expiration.replace('XXX',
|
||||
moment.unix(f.delay * 86400 + f.created_at).locale(window.navigator.language).format('LLLL')
|
||||
);
|
||||
content.push(
|
||||
'<li>— ',
|
||||
'<a href="', f.url, '">',
|
||||
f.name,
|
||||
'</a> (',
|
||||
filesize(f.size),
|
||||
', ',
|
||||
expires,
|
||||
')',
|
||||
'</li>',
|
||||
);
|
||||
content += `<li>— <a href="${f.url}">${f.name}</a>
|
||||
(${filesize(f.size)}, ${expires})
|
||||
</li>`;
|
||||
}
|
||||
$('#files-ul').html(content.join(''));
|
||||
$('#files-ul').html(content);
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
function notify(title, body) {
|
||||
if (!'Notification' in window || typeof(Notification) === 'undefined') {
|
||||
console.log("This browser does not support desktop notification, cannot send following message: "+title+" "+body);
|
||||
console.log(`This browser does not support desktop notification, cannot send following message: ${title} ${body}`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -68,14 +68,14 @@ function copyAllToClipboard(event) {
|
|||
|
||||
// Add item to localStorage
|
||||
function addItem(name, url, size, del_at_first_view, created_at, delay, short, token) {
|
||||
var files = localStorage.getItem(window.prefix + 'files');
|
||||
var files = localStorage.getItem(`${window.prefix}files`);
|
||||
if (files === null) {
|
||||
files = new Array();
|
||||
} else {
|
||||
files = JSON.parse(files);
|
||||
}
|
||||
files.push({ name: name, short: short, url: url, size: size, del_at_first_view: del_at_first_view, created_at: created_at, delay: delay, token: token });
|
||||
localStorage.setItem(window.prefix + 'files', JSON.stringify(files));
|
||||
localStorage.setItem(`${window.prefix}files`, JSON.stringify(files));
|
||||
}
|
||||
|
||||
// Remove a file block
|
||||
|
@ -192,7 +192,7 @@ function updateMailLink() {
|
|||
for (i = 0; i < a.length; i++) {
|
||||
l.push(a[i].id);
|
||||
}
|
||||
var u = actionURL+'m?links='+JSON.stringify(l);
|
||||
var u = `${actionURL}m?links=${JSON.stringify(l)}`;
|
||||
$('#mailto').attr('href', u);
|
||||
}
|
||||
|
||||
|
@ -240,18 +240,16 @@ function handleFiles(f) {
|
|||
var counter = 0;
|
||||
while (typeof(window.zip.files[filename]) !== 'undefined') {
|
||||
counter += 1;
|
||||
filename = origname.substring(0, origname.lastIndexOf('.')) + '_(' + counter + ')' + origname.substring(origname.lastIndexOf('.'));
|
||||
filename = `${origname.substring(0, origname.lastIndexOf('.'))}_(${counter})${origname.substring(origname.lastIndexOf('.'))}`;
|
||||
}
|
||||
|
||||
window.zip.file(filename, element);
|
||||
|
||||
window.zipSize += element.size;
|
||||
$('#zip-size').text(filesize(window.zipSize));
|
||||
$('#zip-parts').append([
|
||||
'<li>',
|
||||
'— ', escapeHtml(filename), ' (', filesize(element.size), ')',
|
||||
'</li>'
|
||||
].join(''));
|
||||
$('#zip-parts').append(`<li>
|
||||
— ${escapeHtml(filename)} (${filesize(element.size)})
|
||||
</li>`);
|
||||
}
|
||||
} else {
|
||||
if (window.fileList === undefined || window.fileList === null) {
|
||||
|
@ -295,23 +293,32 @@ function uploadFile(i, delay, del_at_first_view) {
|
|||
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>',
|
||||
'</a>',
|
||||
'<div class="card-content">',
|
||||
'<span class="card-title" id="name-', window.fc, '">', name, '</span> <span id="size-', window.fc ,'">(', size,')</span>',
|
||||
'<p id="parts-', window.fc, '"></p>',
|
||||
'</div>',
|
||||
'<div class="progress">',
|
||||
'<div id="progress-', window.fc, '" data-key="', randomkey, '" data-name="', name, '" aria-valuemax="100" aria-valuemin="0" aria-valuenow="0" role="progressbar" class="determinate width-0">',
|
||||
'<span class="sr-only">', name, '0%</span>',
|
||||
'</div>',
|
||||
'</div>',
|
||||
'<div>'].join(''));
|
||||
w.html(`<div class="card">
|
||||
<div>
|
||||
<a href="#" id="destroy-${window.fc}">
|
||||
<i class="right mdi-navigation-close small"></i>
|
||||
</a>
|
||||
<div class="card-content">
|
||||
<span class="card-title"
|
||||
id="name-${window.fc}">${name}</span>
|
||||
<span id="size-${window.fc }">(${size})</span>
|
||||
<p id="parts-${window.fc}"></p>
|
||||
</div>
|
||||
<div class="progress">
|
||||
<div id="progress-${window.fc}"
|
||||
data-key="${randomkey}"
|
||||
data-name="${name}"
|
||||
aria-valuemax="100"
|
||||
aria-valuemin="0"
|
||||
aria-valuenow="0"
|
||||
role="progressbar"
|
||||
class="determinate width-0">
|
||||
<span class="sr-only">${name}0%</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>`);
|
||||
r.prepend(w);
|
||||
$('#destroy-'+window.fc).on('click', function(event) {
|
||||
$(`#destroy-${window.fc}`).on('click', function(event) {
|
||||
event.preventDefault();
|
||||
window.cancelled.push(i);
|
||||
destroyBlock(this);
|
||||
|
@ -350,7 +357,7 @@ function sliceAndUpload(randomkey, i, parts, j, delay, del_at_first_view, short,
|
|||
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);
|
||||
var sl = $(`#parts-${window.fc}`);
|
||||
|
||||
// Get the binary result, different result in IE browsers (see default.html.ep line 27:48)
|
||||
if (isIE == true){
|
||||
|
@ -387,12 +394,12 @@ 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);;
|
||||
data = `${JSON.stringify(data)}XXMOJOXX${JSON.stringify(encrypted)}`;
|
||||
|
||||
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
|
||||
if (window.ws.readyState === 3) {
|
||||
|
@ -403,14 +410,14 @@ function sliceAndUpload(randomkey, i, parts, j, delay, del_at_first_view, short,
|
|||
window.ws.onclose = function() {
|
||||
console.log('Websocket closed, waiting 10sec.');
|
||||
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.onerror = function() {
|
||||
console.log('Error on Websocket, waiting 10sec.');
|
||||
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);
|
||||
});
|
||||
};
|
||||
|
@ -427,7 +434,7 @@ function updateProgressBar(data) {
|
|||
if (data.success) {
|
||||
console.log('Upload successfully cancelled');
|
||||
} else {
|
||||
console.log('Upload cancellation failed: ' + data.msg);
|
||||
console.log(`Upload cancellation failed: ${data.msg}`);
|
||||
}
|
||||
|
||||
// Remove the cancelled index
|
||||
|
@ -463,9 +470,9 @@ function updateProgressBar(data) {
|
|||
var short = data.short;
|
||||
var created_at = data.created_at;
|
||||
|
||||
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');
|
||||
|
||||
if (j + 1 === parts) {
|
||||
|
@ -474,44 +481,44 @@ function updateProgressBar(data) {
|
|||
console.log('Connection is closed.');
|
||||
};
|
||||
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);
|
||||
|
||||
$('#parts-'+window.fc).remove();
|
||||
var n = $('#name-'+window.fc);
|
||||
var s = $('#size-'+window.fc);
|
||||
$(`#parts-${window.fc}`).remove();
|
||||
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 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+' '+moment.unix(delay * 86400 + created_at).locale(window.navigator.language).format('LLLL');
|
||||
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">',
|
||||
'<div class="input-field">',
|
||||
'<span class="prefix big-prefix">',
|
||||
'<a href="', url, '" target="_blank">',
|
||||
'<i class="mdi-file-file-download small" title="', i18n.dlText, '"></i>',
|
||||
'</a>',
|
||||
'<a href="#" id="copyurl-', window.fc, '" title="', i18n.cpText, '">',
|
||||
'<i class="mdi-content-content-copy small"></i>',
|
||||
'</a>',
|
||||
'</span>',
|
||||
'<input id="', short, '" class="form-control link-input white-background" value="', url, '" readonly="" type="text">',
|
||||
'<label class="active" for="', short, '">', i18n.dlText, '</label>',
|
||||
'</div>',
|
||||
'<div class="input-field">',
|
||||
'<a href="', del_url, '" target="_blank" class="prefix big-prefix">',
|
||||
'<i class="mdi-action-delete small" title="', i18n.delText, '"></i>',
|
||||
'</a>',
|
||||
'<input id="delete-', short, '" class="form-control white-background" value="', del_url, '" readonly="" type="text">',
|
||||
'<label class="active" for="delete-', short, '">', i18n.delText, '</label>',
|
||||
'</div>',
|
||||
'</div>'].join(''));
|
||||
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">
|
||||
<div class="input-field">
|
||||
<span class="prefix big-prefix">
|
||||
<a href="${url}" target="_blank">
|
||||
<i class="mdi-file-file-download small" title="${i18n.dlText}"></i>
|
||||
</a>
|
||||
<a href="#" id="copyurl-${window.fc}" title="${i18n.cpText}">
|
||||
<i class="mdi-content-content-copy small"></i>
|
||||
</a>
|
||||
</span>
|
||||
<input id="${short}" class="form-control link-input white-background" value="${url}" readonly="" type="text">
|
||||
<label class="active" for="${short}">${i18n.dlText}</label>
|
||||
</div>
|
||||
<div class="input-field">
|
||||
<a href="${del_url}" target="_blank" class="prefix big-prefix">
|
||||
<i class="mdi-action-delete small" title="${i18n.delText}"></i>
|
||||
</a>
|
||||
<input id="delete-${short}" class="form-control white-background" value="${del_url}" readonly="" type="text">
|
||||
<label class="active" for="delete-${short}">${i18n.delText}</label>
|
||||
</div>
|
||||
</div>`);
|
||||
} else {
|
||||
n.html(n.html()+' '+s.html());
|
||||
n.html(`${n.html()} ${s.html()}`);
|
||||
}
|
||||
s.remove();
|
||||
|
||||
|
@ -521,7 +528,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);
|
||||
});
|
||||
|
@ -531,7 +538,12 @@ function updateProgressBar(data) {
|
|||
// Add copy all and mailto buttons
|
||||
var misc = $('#misc');
|
||||
if (misc.html() === '' && !isGuest) {
|
||||
misc.html('<a href="#" id="copyall" class="btn btn-info">'+i18n.copyAll+'</a> <a id="mailto" href="'+actionURL+'m?links='+links+'" class="btn btn-info">'+i18n.mailTo+'</a>');
|
||||
misc.html(`<a href="#"
|
||||
id="copyall"
|
||||
class="btn btn-info">${i18n.copyAll}</a>
|
||||
<a id="mailto"
|
||||
href="${actionURL}m?links=${links}"
|
||||
class="btn btn-info">${i18n.mailTo}</a>`);
|
||||
$('#copyall').on('click', copyAllToClipboard);
|
||||
} else {
|
||||
updateMailLink();
|
||||
|
@ -574,7 +586,7 @@ function updateProgressBar(data) {
|
|||
var wClass = percent.toString().replace('.', '-');
|
||||
dp.removeClass();
|
||||
dp.addClass('determinate');
|
||||
dp.addClass('width-'+wClass);
|
||||
dp.addClass(`width-${wClass}`);
|
||||
dp.attr('aria-valuenow', percent);
|
||||
|
||||
// Encrypt and upload next slice
|
||||
|
@ -593,15 +605,15 @@ 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 n = $(`#name-${window.fc}`);
|
||||
var p = $(`#progress-${window.fc}`);
|
||||
var d = $('<div>');
|
||||
|
||||
p.parent().remove();
|
||||
d.addClass('card pink');
|
||||
d.html(['<div class="card-content white-text">',
|
||||
'<strong>', msg, '</strong>',
|
||||
'</div>'].join(''));
|
||||
d.html(`<div class="card-content white-text">
|
||||
<strong>${msg}</strong>
|
||||
</div>`);
|
||||
n.parent().append(d);
|
||||
|
||||
// Upload next file
|
||||
|
@ -653,7 +665,7 @@ function spawnWebsocket(i, callback) {
|
|||
ws.onerror = function() {
|
||||
console.log('error');
|
||||
if (i < 5 && callback !== undefined) {
|
||||
console.log('Retrying to send file (try '+i+' of 5)');
|
||||
console.log(`Retrying to send file (try ${i} of 5)`);
|
||||
window.ws = spawnWebsocket(i + 1, callback);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
% # vim:set sts=4 sw=4 ts=4 ft=javascript expandtab:
|
||||
function findItem(name) {
|
||||
var files = localStorage.getItem(window.prefix + 'files');
|
||||
var files = localStorage.getItem(`${window.prefix}files`);
|
||||
if (files === null) {
|
||||
files = new Array();
|
||||
} else {
|
||||
|
@ -19,7 +19,7 @@ function updateMailtoLink() {
|
|||
var subject = document.getElementById('subject');
|
||||
var text = document.getElementById('body');
|
||||
|
||||
btn.href = 'mailto:'+encodeURIComponent(emails.value)+'?subject='+encodeURIComponent(subject.value)+'&body='+encodeURIComponent(text.value);
|
||||
btn.href = `mailto:${encodeURIComponent(emails.value)}?subject=${encodeURIComponent(subject.value)}&body=${encodeURIComponent(text.value)}`;
|
||||
}
|
||||
function populateBody() {
|
||||
var links = [
|
||||
|
@ -37,16 +37,16 @@ function populateBody() {
|
|||
var item = findItem(name);
|
||||
if (item !== null && item !== undefined) {
|
||||
var limit = (item.delay === 0) ? null : moment.unix(item.delay * 86400 + item.created_at).locale(window.navigator.language).format('LLLL');
|
||||
text = text+'- '+item.name+'<%= l(':') %> '+item.url;
|
||||
text += `- ${item.name}<%= l(':') %> ${item.url}`;
|
||||
if (limit !== null) {
|
||||
text = text+"\n (<%= l('deadline: ') %>"+limit+')';
|
||||
text += `\n (<%= l('deadline: ') %>${limit})`;
|
||||
}
|
||||
text = text+"\n";
|
||||
text += "\n";
|
||||
}
|
||||
});
|
||||
|
||||
% if (!defined(config('ldap')) && !defined(config('htpasswd'))) {
|
||||
text = text+"\n-- \n<%= l('Share your files in total privacy on %1', url_for('/')->to_abs) %>";
|
||||
text += "\n-- \n<%= l('Share your files in total privacy on %1', url_for('/')->to_abs) %>";
|
||||
% }
|
||||
tArea = document.getElementById('body').value = text;
|
||||
updateMailtoLink();
|
||||
|
|
Loading…
Reference in New Issue