]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
Source file download in new Utils function
authorDaniel Tschlatscher <d.tschlatscher@proxmox.com>
Wed, 4 Jan 2023 12:56:34 +0000 (13:56 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 4 Jan 2023 13:32:59 +0000 (14:32 +0100)
Adds a function for downloading a file from a remote URL in the Utils
class and uses it to revise one similar usage in FileBrowser.js

Signed-off-by: Daniel Tschlatscher <d.tschlatscher@proxmox.com>
Tested-by: Stefan Sterz <s.sterz@proxmox.com>
Reviewed-by: Stefan Sterz <s.sterz@proxmox.com>
src/Utils.js
src/window/FileBrowser.js

index 7255e3f98689539ba4503aa5d64e08e5f705aa86..ef0c2b8ed8884b6dbd25eb1a6a641f1b8680aaa7 100644 (file)
@@ -1360,6 +1360,19 @@ utilities: {
        }
        return `<span class="${cls}" style="${style}">${string}</span>`;
     },
+
+    // Setting filename here when downloading from a remote url sometimes fails in chromium browsers
+    // because of a bug when using attribute download in conjunction with a self signed certificate.
+    // For more info see https://bugs.chromium.org/p/chromium/issues/detail?id=993362
+    downloadAsFile: function(source, fileName) {
+       let hiddenElement = document.createElement('a');
+       hiddenElement.href = source;
+       hiddenElement.target = '_blank';
+       if (fileName) {
+           hiddenElement.download = fileName;
+       }
+       hiddenElement.click();
+    },
 },
 
     singleton: true,
index a519d6bad5aa07b19e64c0676d35526bb35b5b51..4e4c639fdefc1f3886f664f23dcfeeb386736d38 100644 (file)
@@ -101,18 +101,17 @@ Ext.define("Proxmox.window.FileBrowser", {
            let params = { ...view.extraParams };
            params.filepath = data.filepath;
 
-           let atag = document.createElement('a');
-           atag.download = view.downloadPrefix + data.text;
+           let filename = view.downloadPrefix + data.text;
            if (data.type === 'd') {
                if (tar) {
                    params.tar = 1;
-                   atag.download += ".tar.zst";
+                   filename += ".tar.zst";
                } else {
-                   atag.download += ".zip";
+                   filename += ".zip";
                }
            }
-           atag.href = me.buildUrl(view.downloadURL, params);
-           atag.click();
+
+           Proxmox.Utils.downloadAsFile(me.buildUrl(view.downloadURL, params), filename);
        },
 
        fileChanged: function() {