🐛 Try to avoid clients constantly hitting /download/XXX

This commit is contained in:
Luc Didry 2020-12-03 12:46:22 +01:00
parent a82ad6c300
commit 1adf8e7455
No known key found for this signature in database
GPG Key ID: EA868E12D0257E3C
4 changed files with 75 additions and 50 deletions

View File

@ -41,7 +41,7 @@ msgstr "%1 sent you files"
msgid "%1 used your invitation to send you files:"
msgstr "%1 used your invitation to send you files:"
#: lib/Lufi/Controller/Invitation.pm:159 lib/Lufi/Controller/Invitation.pm:84 themes/default/templates/invitations/my_invitations.html.ep:51 themes/default/templates/invitations/my_invitations.html.ep:52 themes/default/templates/invitations/my_invitations.html.ep:53 themes/default/templates/invitations/notification_files_sent.mail.ep:12
#: lib/Lufi/Controller/Invitation.pm:160 lib/Lufi/Controller/Invitation.pm:85 themes/default/templates/invitations/my_invitations.html.ep:51 themes/default/templates/invitations/my_invitations.html.ep:52 themes/default/templates/invitations/my_invitations.html.ep:53 themes/default/templates/invitations/notification_files_sent.mail.ep:12
msgid "%A %d %B %Y at %T"
msgstr "%A %d %B %Y at %T"
@ -118,7 +118,7 @@ msgstr "Click on the following URL to upload files on Lufi:"
msgid "Click to open the file browser"
msgstr "Click to open the file browser"
#: themes/default/templates/delays.html.ep:38 themes/default/templates/invitations/my_invitations.html.ep:80
#: themes/default/templates/delays.html.ep:42 themes/default/templates/invitations/my_invitations.html.ep:80
msgid "Close"
msgstr "Close"
@ -178,7 +178,7 @@ msgstr "Delete selected files"
msgid "Deletion link"
msgstr "Deletion link"
#: themes/default/templates/delays.html.ep:8
#: themes/default/templates/delays.html.ep:9
msgid "Don't worry: if a user begins to download the file before the expiration and the download ends after the expiration, he will be able to get the file."
msgstr "Don't worry: if a user begins to download the file before the expiration and the download ends after the expiration, he will be able to get the file."
@ -339,7 +339,7 @@ msgstr "How to install the software on my server?"
msgid "How to report an illegal file?"
msgstr "How to report an illegal file?"
#: themes/default/templates/delays.html.ep:7
#: themes/default/templates/delays.html.ep:8
msgid "If you choose a delay, the file will be deleted after that delay."
msgstr "If you choose a delay, the file will be deleted after that delay."
@ -364,12 +364,12 @@ msgid "Invert selection"
msgstr "Invert selection"
#. ($i->guest_mail, $url)
#: lib/Lufi/Controller/Invitation.pm:171
#: lib/Lufi/Controller/Invitation.pm:172
msgid "Invitation resent to %1.<br> URL: %2"
msgstr "Invitation resent to %1.<br> URL: %2"
#. ($invitation->guest_mail, $url)
#: lib/Lufi/Controller/Invitation.pm:87
#: lib/Lufi/Controller/Invitation.pm:88
msgid "Invitation sent to %1.<br> URL: %2"
msgstr "Invitation sent to %1.<br> URL: %2"
@ -534,7 +534,7 @@ msgstr "Show zip content"
msgid "Signin"
msgstr "Signin"
#: lib/Lufi/Controller/Invitation.pm:283 themes/default/templates/invitations/exception.html.ep:16
#: lib/Lufi/Controller/Invitation.pm:284 themes/default/templates/invitations/exception.html.ep:16
msgid "Sorry, the invitation doesnt exist. Are you sure you are on the right URL?"
msgstr "Sorry, the invitation doesnt exist. Are you sure you are on the right URL?"
@ -556,7 +556,7 @@ msgid "Sorry, your invitation has expired or has been deleted. Please contact %1
msgstr "Sorry, your invitation has expired or has been deleted. Please contact %1 to have another invitation."
#. ($invitation->ldap_user_mail)
#: lib/Lufi/Controller/Invitation.pm:276
#: lib/Lufi/Controller/Invitation.pm:277
msgid "The URLs of your files have been sent by email to %1."
msgstr "The URLs of your files have been sent by email to %1."
@ -581,7 +581,7 @@ msgid "The email subject can't be empty."
msgstr "The email subject can't be empty."
#. ($expire_at, $max_expire_at)
#: lib/Lufi/Controller/Invitation.pm:51
#: lib/Lufi/Controller/Invitation.pm:52
msgid "The expiration delay (%1) is not between 1 and %2 days."
msgstr "The expiration delay (%1) is not between 1 and %2 days."
@ -599,17 +599,17 @@ msgid "The following email addresses are not valid: %1"
msgstr "The following email addresses are not valid: %1"
#. ($guest_mail)
#: lib/Lufi/Controller/Invitation.pm:48
#: lib/Lufi/Controller/Invitation.pm:49
msgid "The guest email address (%1) is unvalid."
msgstr "The guest email address (%1) is unvalid."
#. ($i->token, $i->guest_mail)
#: lib/Lufi/Controller/Invitation.pm:150
#: lib/Lufi/Controller/Invitation.pm:151
msgid "The invitation %1 cant be resent: %2 has already sent files.<br>Please create a new invitation."
msgstr "The invitation %1 cant be resent: %2 has already sent files.<br>Please create a new invitation."
#. ($i->token)
#: lib/Lufi/Controller/Invitation.pm:130
#: lib/Lufi/Controller/Invitation.pm:131
msgid "The invitation %1 has been deleted."
msgstr "The invitation %1 has been deleted."
@ -657,7 +657,7 @@ msgstr "This invitation is normally hidden"
msgid "This invitation is valid until %1."
msgstr "This invitation is valid until %1."
#: themes/default/templates/delays.html.ep:10
#: themes/default/templates/delays.html.ep:13
msgid "This server sets limitations according to the file size. The expiration delay of your file will be the minimum between what you choose and the following limitations:"
msgstr "This server sets limitations according to the file size. The expiration delay of your file will be the minimum between what you choose and the following limitations:"
@ -673,6 +673,10 @@ msgstr "URL"
msgid "Unable to copy the link(s) to your clipboard"
msgstr "Unable to copy the link(s) to your clipboard"
#: themes/default/templates/partial/render.js.ep:13
msgid "Unable to download the file: too much unsuccessful attempts to open a websocket. Please, contact the administrator."
msgstr ""
#. ($short)
#: lib/Lufi/Controller/Files.pm:433
msgid "Unable to get counter for %1. The file does not exists. It will be removed from your localStorage."
@ -773,17 +777,17 @@ msgstr "Your file is too big: %1 (maximum size allowed: %2)"
msgid "Your password is not valid. Please refresh the page to retry."
msgstr "Your password is not valid. Please refresh the page to retry."
#: themes/default/templates/partial/render.js.ep:13
#: themes/default/templates/partial/render.js.ep:14
msgid "Zip content:"
msgstr "Zip content:"
#. (format_bytes($keys[$i])
#: themes/default/templates/delays.html.ep:20
#: themes/default/templates/delays.html.ep:24
msgid "between %1 and %2, the file will be kept %3 day(s)."
msgstr "between %1 and %2, the file will be kept %3 day(s)."
#. (format_bytes($keys[$i])
#: themes/default/templates/delays.html.ep:22
#: themes/default/templates/delays.html.ep:26
msgid "between %1 and %2, the file will be kept forever."
msgstr "between %1 and %2, the file will be kept forever."
@ -796,12 +800,12 @@ msgid "expires on XXX"
msgstr "expires on XXX"
#. (format_bytes($keys[$i])
#: themes/default/templates/delays.html.ep:26
#: themes/default/templates/delays.html.ep:30
msgid "for %1 and more, the file will be kept %2 day(s)"
msgstr "for %1 and more, the file will be kept %2 day(s)"
#. (format_bytes($keys[$i])
#: themes/default/templates/delays.html.ep:28
#: themes/default/templates/delays.html.ep:32
msgid "for %1 and more, the file will be kept forever."
msgstr "for %1 and more, the file will be kept forever."

View File

@ -41,7 +41,7 @@ msgstr ""
msgid "%1 used your invitation to send you files:"
msgstr ""
#: lib/Lufi/Controller/Invitation.pm:159 lib/Lufi/Controller/Invitation.pm:84 themes/default/templates/invitations/my_invitations.html.ep:51 themes/default/templates/invitations/my_invitations.html.ep:52 themes/default/templates/invitations/my_invitations.html.ep:53 themes/default/templates/invitations/notification_files_sent.mail.ep:12
#: lib/Lufi/Controller/Invitation.pm:160 lib/Lufi/Controller/Invitation.pm:85 themes/default/templates/invitations/my_invitations.html.ep:51 themes/default/templates/invitations/my_invitations.html.ep:52 themes/default/templates/invitations/my_invitations.html.ep:53 themes/default/templates/invitations/notification_files_sent.mail.ep:12
msgid "%A %d %B %Y at %T"
msgstr ""
@ -118,7 +118,7 @@ msgstr ""
msgid "Click to open the file browser"
msgstr ""
#: themes/default/templates/delays.html.ep:38 themes/default/templates/invitations/my_invitations.html.ep:80
#: themes/default/templates/delays.html.ep:42 themes/default/templates/invitations/my_invitations.html.ep:80
msgid "Close"
msgstr ""
@ -178,7 +178,7 @@ msgstr ""
msgid "Deletion link"
msgstr ""
#: themes/default/templates/delays.html.ep:8
#: themes/default/templates/delays.html.ep:9
msgid "Don't worry: if a user begins to download the file before the expiration and the download ends after the expiration, he will be able to get the file."
msgstr ""
@ -339,7 +339,7 @@ msgstr ""
msgid "How to report an illegal file?"
msgstr ""
#: themes/default/templates/delays.html.ep:7
#: themes/default/templates/delays.html.ep:8
msgid "If you choose a delay, the file will be deleted after that delay."
msgstr ""
@ -364,12 +364,12 @@ msgid "Invert selection"
msgstr ""
#. ($i->guest_mail, $url)
#: lib/Lufi/Controller/Invitation.pm:171
#: lib/Lufi/Controller/Invitation.pm:172
msgid "Invitation resent to %1.<br> URL: %2"
msgstr ""
#. ($invitation->guest_mail, $url)
#: lib/Lufi/Controller/Invitation.pm:87
#: lib/Lufi/Controller/Invitation.pm:88
msgid "Invitation sent to %1.<br> URL: %2"
msgstr ""
@ -534,7 +534,7 @@ msgstr ""
msgid "Signin"
msgstr ""
#: lib/Lufi/Controller/Invitation.pm:283 themes/default/templates/invitations/exception.html.ep:16
#: lib/Lufi/Controller/Invitation.pm:284 themes/default/templates/invitations/exception.html.ep:16
msgid "Sorry, the invitation doesnt exist. Are you sure you are on the right URL?"
msgstr ""
@ -556,7 +556,7 @@ msgid "Sorry, your invitation has expired or has been deleted. Please contact %1
msgstr ""
#. ($invitation->ldap_user_mail)
#: lib/Lufi/Controller/Invitation.pm:276
#: lib/Lufi/Controller/Invitation.pm:277
msgid "The URLs of your files have been sent by email to %1."
msgstr ""
@ -581,7 +581,7 @@ msgid "The email subject can't be empty."
msgstr ""
#. ($expire_at, $max_expire_at)
#: lib/Lufi/Controller/Invitation.pm:51
#: lib/Lufi/Controller/Invitation.pm:52
msgid "The expiration delay (%1) is not between 1 and %2 days."
msgstr ""
@ -599,17 +599,17 @@ msgid "The following email addresses are not valid: %1"
msgstr ""
#. ($guest_mail)
#: lib/Lufi/Controller/Invitation.pm:48
#: lib/Lufi/Controller/Invitation.pm:49
msgid "The guest email address (%1) is unvalid."
msgstr ""
#. ($i->token, $i->guest_mail)
#: lib/Lufi/Controller/Invitation.pm:150
#: lib/Lufi/Controller/Invitation.pm:151
msgid "The invitation %1 cant be resent: %2 has already sent files.<br>Please create a new invitation."
msgstr ""
#. ($i->token)
#: lib/Lufi/Controller/Invitation.pm:130
#: lib/Lufi/Controller/Invitation.pm:131
msgid "The invitation %1 has been deleted."
msgstr ""
@ -657,7 +657,7 @@ msgstr ""
msgid "This invitation is valid until %1."
msgstr ""
#: themes/default/templates/delays.html.ep:10
#: themes/default/templates/delays.html.ep:13
msgid "This server sets limitations according to the file size. The expiration delay of your file will be the minimum between what you choose and the following limitations:"
msgstr ""
@ -673,6 +673,10 @@ msgstr ""
msgid "Unable to copy the link(s) to your clipboard"
msgstr ""
#: themes/default/templates/partial/render.js.ep:13
msgid "Unable to download the file: too much unsuccessful attempts to open a websocket. Please, contact the administrator."
msgstr ""
#. ($short)
#: lib/Lufi/Controller/Files.pm:433
msgid "Unable to get counter for %1. The file does not exists. It will be removed from your localStorage."
@ -773,17 +777,17 @@ msgstr ""
msgid "Your password is not valid. Please refresh the page to retry."
msgstr ""
#: themes/default/templates/partial/render.js.ep:13
#: themes/default/templates/partial/render.js.ep:14
msgid "Zip content:"
msgstr ""
#. (format_bytes($keys[$i])
#: themes/default/templates/delays.html.ep:20
#: themes/default/templates/delays.html.ep:24
msgid "between %1 and %2, the file will be kept %3 day(s)."
msgstr ""
#. (format_bytes($keys[$i])
#: themes/default/templates/delays.html.ep:22
#: themes/default/templates/delays.html.ep:26
msgid "between %1 and %2, the file will be kept forever."
msgstr ""
@ -796,12 +800,12 @@ msgid "expires on XXX"
msgstr ""
#. (format_bytes($keys[$i])
#: themes/default/templates/delays.html.ep:26
#: themes/default/templates/delays.html.ep:30
msgid "for %1 and more, the file will be kept %2 day(s)"
msgstr ""
#. (format_bytes($keys[$i])
#: themes/default/templates/delays.html.ep:28
#: themes/default/templates/delays.html.ep:32
msgid "for %1 and more, the file will be kept forever."
msgstr ""

View File

@ -47,6 +47,7 @@ function addAlert(msg) {
// Spawn WebSocket
function spawnWebsocket(pa) {
console.log('Spawning websocket…');
var ws = new WebSocket(ws_url);
ws.onopen = function() {
console.log('Connection is established!');
@ -62,8 +63,13 @@ function spawnWebsocket(pa) {
ws.onclose = function() {
console.log('Connection is closed');
if (!window.completed) {
console.log('Connection closed. Retrying to get slice '+pa);
window.ws = spawnWebsocket(pa);
window.attempts++;
if (window.attempts < 10) {
console.log('Connection closed. Retrying to get slice '+pa);
window.ws = spawnWebsocket(pa);
} else {
alert(i18n.tooMuchAttempts);
}
}
}
ws.onmessage = function(e) {
@ -71,6 +77,9 @@ function spawnWebsocket(pa) {
var json = res.shift();
var data = JSON.parse(json);
// Reset counter since we succeded to open a websocket and got a message
window.attempts = 0;
if (data.msg !== undefined) {
addAlert(data.msg);
console.log(data.msg);
@ -78,6 +87,7 @@ function spawnWebsocket(pa) {
$('.file-abort').addClass('hide');
}
window.onbeforeunload = null;
window.attempts = 10;
} else {
console.log('Getting slice '+(data.part + 1)+' of '+data.total);
var slice = JSON.parse(res.shift());
@ -203,8 +213,13 @@ function spawnWebsocket(pa) {
}
}
ws.onerror = function() {
console.log('Error. Retrying to get slice '+pa);
window.ws = spawnWebsocket(pa);
window.attempts++;
if (window.attempts < 10) {
console.log('Error. Retrying to get slice '+pa);
window.ws = spawnWebsocket(pa);
} else {
alert(i18n.tooMuchAttempts);
}
}
return ws;
}
@ -225,6 +240,7 @@ $(document).ready(function(){
window.a = new Array();
window.key = pageKey();
window.completed = false;
window.attempts = 0;
if (key !== '=') {
var go = true;

View File

@ -1,14 +1,15 @@
% # vim:set sts=4 sw=4 ts=4 ft=javascript expandtab:
var ws_url = '<%= url_for('download')->to_abs().stash('file') %>';
var i18n = {
aborted1: '<%= l('Download aborted.') %>',
aborted2: '<%= l('Click here to refresh the page and restart the download.') %>',
badkey: '<%= l('It seems that the key in your URL is incorrect. Please, verify your URL.') %>',
confirmExit: '<%= l('You have attempted to leave this page. The download will be canceled. Are you sure?') %>',
download: '<%= l('Get the file') %>',
fileDownloaded: '<%= l('File downloaded') %>',
loading: '<%= l('Asking for file part XX1 of %1', stash('nbslices')) %>',
nokey: '<%= l('You don\'t seem to have a key in your URL. You won\'t be able to decrypt the file. Download canceled.') %>',
showZipContent: '<%= l('Show zip content') %>',
zipContent: '<%= l('Zip content:') %>'
aborted1: '<%= l('Download aborted.') %>',
aborted2: '<%= l('Click here to refresh the page and restart the download.') %>',
badkey: '<%= l('It seems that the key in your URL is incorrect. Please, verify your URL.') %>',
confirmExit: '<%= l('You have attempted to leave this page. The download will be canceled. Are you sure?') %>',
download: '<%= l('Get the file') %>',
fileDownloaded: '<%= l('File downloaded') %>',
loading: '<%= l('Asking for file part XX1 of %1', stash('nbslices')) %>',
nokey: '<%= l('You don\'t seem to have a key in your URL. You won\'t be able to decrypt the file. Download canceled.') %>',
showZipContent: '<%= l('Show zip content') %>',
tooMuchAttempts: '<%= l('Unable to download the file: too much unsuccessful attempts to open a websocket. Please, contact the administrator.') %>',
zipContent: '<%= l('Zip content:') %>'
}