浏览代码

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 <[email protected]>
Nicola Murino 1 年之前
父节点
当前提交
c9d4920e81

+ 1 - 0
static/locales/en/translation.json

@@ -282,6 +282,7 @@
         "select_across_pages": "Select across pages",
         "select_across_pages": "Select across pages",
         "download": "Download",
         "download": "Download",
         "download_ready": "Your download is ready",
         "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",
         "move_copy": "Move or copy",
         "share": "Share",
         "share": "Share",
         "home": "Home",
         "home": "Home",

+ 1 - 0
static/locales/it/translation.json

@@ -282,6 +282,7 @@
         "select_across_pages": "Seleziona tra le pagine",
         "select_across_pages": "Seleziona tra le pagine",
         "download": "Scarica",
         "download": "Scarica",
         "download_ready": "Il tuo download è pronto",
         "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",
         "move_copy": "Sposta o copia",
         "share": "Condividi",
         "share": "Condividi",
         "home": "Home",
         "home": "Home",

+ 28 - 2
templates/webclient/files.html

@@ -2200,6 +2200,26 @@ explicit grant from the SFTPGo Team ([email protected]).
     $(document).on("i18nshow", function(){
     $(document).on("i18nshow", function(){
         KTDatatablesServerSide.init();
         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", {
         var dropzone =  new Dropzone("#upload_files", {
             url: "{{.FilesURL}}?path={{.CurrentDir}}",
             url: "{{.FilesURL}}?path={{.CurrentDir}}",
             paramName: "filenames",
             paramName: "filenames",
@@ -2214,7 +2234,9 @@ explicit grant from the SFTPGo Team ([email protected]).
             init: function() {
             init: function() {
                 var dropzone = this;
                 var dropzone = this;
                 $("#upload_files_button").click(function(){
                 $("#upload_files_button").click(function(){
-                   uploadFiles(dropzone.getAcceptedFiles());
+                    if (canUpload()){
+                        uploadFiles(dropzone.getAcceptedFiles());
+                    }
                 });
                 });
             }
             }
         });
         });
@@ -2228,6 +2250,7 @@ explicit grant from the SFTPGo Team ([email protected]).
                     node.textContent = file.fullPath;
                     node.textContent = file.fullPath;
                 }
                 }
             }
             }
+            lastAddedFile = Date.now();
         });
         });
 
 
         var dropzoneEmpty =  new Dropzone("#upload_files_empty", {
         var dropzoneEmpty =  new Dropzone("#upload_files_empty", {
@@ -2244,7 +2267,9 @@ explicit grant from the SFTPGo Team ([email protected]).
             init: function() {
             init: function() {
                 var dropzoneEmpty = this;
                 var dropzoneEmpty = this;
                 $("#upload_files_empty_button").click(function(){
                 $("#upload_files_empty_button").click(function(){
-                   uploadFiles(dropzoneEmpty.getAcceptedFiles());
+                    if (canUpload()){
+                        uploadFiles(dropzoneEmpty.getAcceptedFiles());
+                    }
                 });
                 });
             }
             }
         });
         });
@@ -2258,6 +2283,7 @@ explicit grant from the SFTPGo Team ([email protected]).
                     node.textContent = file.fullPath;
                     node.textContent = file.fullPath;
                 }
                 }
             }
             }
+            lastAddedFile = Date.now();
         });
         });
 
 
         $('#modal_video_player').on('hide.bs.modal', function () {
         $('#modal_video_player').on('hide.bs.modal', function () {

+ 24 - 1
templates/webclient/shareupload.html

@@ -162,6 +162,26 @@ explicit grant from the SFTPGo Team ([email protected]).
     }
     }
 
 
     KTUtil.onDOMContentLoaded(function () {
     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", {
         var dropzone =  new Dropzone("#upload_files", {
             url: "{{.UploadBasePath}}",
             url: "{{.UploadBasePath}}",
             paramName: "filenames",
             paramName: "filenames",
@@ -182,7 +202,9 @@ explicit grant from the SFTPGo Team ([email protected]).
             init: function() {
             init: function() {
                 var dropzone = this;
                 var dropzone = this;
                 $("#upload_files_button").click(function(){
                 $("#upload_files_button").click(function(){
-                   uploadFiles(dropzone.getAcceptedFiles());
+                    if (canUpload()){
+                        uploadFiles(dropzone.getAcceptedFiles());
+                    }
                 });
                 });
             }
             }
         });
         });
@@ -196,6 +218,7 @@ explicit grant from the SFTPGo Team ([email protected]).
                     node.textContent = file.fullPath;
                     node.textContent = file.fullPath;
                 }
                 }
             }
             }
+            lastAddedFile = Date.now();
         });
         });
     });
     });