From c9d4920e81f97d046ee0a9d07b562e391905732f Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Thu, 3 Oct 2024 19:06:33 +0200 Subject: [PATCH] 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 --- static/locales/en/translation.json | 1 + static/locales/it/translation.json | 1 + templates/webclient/files.html | 30 ++++++++++++++++++++++++++-- templates/webclient/shareupload.html | 25 ++++++++++++++++++++++- 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/static/locales/en/translation.json b/static/locales/en/translation.json index 0843f89b..154560c7 100644 --- a/static/locales/en/translation.json +++ b/static/locales/en/translation.json @@ -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", diff --git a/static/locales/it/translation.json b/static/locales/it/translation.json index cafcab77..3e3de6f2 100644 --- a/static/locales/it/translation.json +++ b/static/locales/it/translation.json @@ -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", diff --git a/templates/webclient/files.html b/templates/webclient/files.html index 6e1722c0..bec318d7 100644 --- a/templates/webclient/files.html +++ b/templates/webclient/files.html @@ -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 () { diff --git a/templates/webclient/shareupload.html b/templates/webclient/shareupload.html index 8afc74ab..eaeb5e7d 100644 --- a/templates/webclient/shareupload.html +++ b/templates/webclient/shareupload.html @@ -162,6 +162,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", @@ -182,7 +202,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()); + } }); } }); @@ -196,6 +218,7 @@ explicit grant from the SFTPGo Team (support@sftpgo.com). node.textContent = file.fullPath; } } + lastAddedFile = Date.now(); }); });