WebClient: make sure to upload files after the queue is populated

Ugly hack to prevent to start uploading files before the upload
queue is fully populated.

We should investigate if there is a better way

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino 2024-10-03 19:06:33 +02:00
parent 46e64706ea
commit 2ecd20d444
No known key found for this signature in database
GPG key ID: 935D2952DEC4EECF
4 changed files with 54 additions and 3 deletions

View file

@ -282,6 +282,7 @@
"select_across_pages": "Select across pages",
"download": "Download",
"download_ready": "Your download is ready",
"upload_queue_not_ready": "The upload queue is still loading, please try again in a few moments",
"move_copy": "Move or copy",
"share": "Share",
"home": "Home",

View file

@ -282,6 +282,7 @@
"select_across_pages": "Seleziona tra le pagine",
"download": "Scarica",
"download_ready": "Il tuo download è pronto",
"upload_queue_not_ready": "La coda di caricamento è in fase di elaborazione, riprova tra qualche istante",
"move_copy": "Sposta o copia",
"share": "Condividi",
"home": "Home",

View file

@ -2200,6 +2200,26 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
$(document).on("i18nshow", function(){
KTDatatablesServerSide.init();
var lastAddedFile = Date.now();
function canUpload() {
// Ugly hack to detect if we are still loading a large file list when the user try to upload files.
// The Dropzone addedfiles event is fired for directories before the files within them are added to the queue.
// TODO: investigate if there is a better way.
if (Date.now() - lastAddedFile < 500) {
ModalAlert.fire({
text: $.t('fs.upload_queue_not_ready'),
icon: "warning",
confirmButtonText: $.t('general.ok'),
customClass: {
confirmButton: "btn btn-primary"
}
});
return false;
}
return true;
}
var dropzone = new Dropzone("#upload_files", {
url: "{{.FilesURL}}?path={{.CurrentDir}}",
paramName: "filenames",
@ -2214,7 +2234,9 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
init: function() {
var dropzone = this;
$("#upload_files_button").click(function(){
uploadFiles(dropzone.getAcceptedFiles());
if (canUpload()){
uploadFiles(dropzone.getAcceptedFiles());
}
});
}
});
@ -2228,6 +2250,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
node.textContent = file.fullPath;
}
}
lastAddedFile = Date.now();
});
var dropzoneEmpty = new Dropzone("#upload_files_empty", {
@ -2244,7 +2267,9 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
init: function() {
var dropzoneEmpty = this;
$("#upload_files_empty_button").click(function(){
uploadFiles(dropzoneEmpty.getAcceptedFiles());
if (canUpload()){
uploadFiles(dropzoneEmpty.getAcceptedFiles());
}
});
}
});
@ -2258,6 +2283,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
node.textContent = file.fullPath;
}
}
lastAddedFile = Date.now();
});
$('#modal_video_player').on('hide.bs.modal', function () {

View file

@ -169,6 +169,26 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
}
KTUtil.onDOMContentLoaded(function () {
var lastAddedFile = Date.now();
function canUpload() {
// Ugly hack to detect if we are still loading a large file list when the user try to upload files.
// The Dropzone addedfiles event is fired for directories before the files within them are added to the queue.
// TODO: investigate if there is a better way.
if (Date.now() - lastAddedFile < 500) {
ModalAlert.fire({
text: $.t('fs.upload_queue_not_ready'),
icon: "warning",
confirmButtonText: $.t('general.ok'),
customClass: {
confirmButton: "btn btn-primary"
}
});
return false;
}
return true;
}
var dropzone = new Dropzone("#upload_files", {
url: "{{.UploadBasePath}}",
paramName: "filenames",
@ -189,7 +209,9 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
init: function() {
var dropzone = this;
$("#upload_files_button").click(function(){
uploadFiles(dropzone.getAcceptedFiles());
if (canUpload()){
uploadFiles(dropzone.getAcceptedFiles());
}
});
}
});
@ -203,6 +225,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
node.textContent = file.fullPath;
}
}
lastAddedFile = Date.now();
});
});