]> git.proxmox.com Git - pve-manager.git/commitdiff
ui: utils: split out general "load local file" helper
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 19 May 2021 09:07:03 +0000 (11:07 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 19 May 2021 09:10:16 +0000 (11:10 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
www/manager6/Utils.js

index e927a2fd7d0f3e9dd3050860b67096af7244edef..d9567979e6ffbb353f87f2f99ebf3adc998cdb3c 100644 (file)
@@ -1500,18 +1500,19 @@ Ext.define('PVE.Utils', {
     },
 
     loadSSHKeyFromFile: function(file, callback) {
-       // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
-       // a user@host comment, 1420 for 8192 bits; current max is 16kbit
-       // assume: 740*8 for max. 32kbit (5920 byte file)
-       // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
-       if (file.size > 8192) {
-           Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size);
+       // ssh-keygen produces ~ 740 bytes for a 4096 bit RSA key,  current max is 16 kbit, so assume:
+       // 740 * 8 for max. 32kbit (5920 bytes), round upwards to 8192 bytes, leaves lots of comment space
+       PVE.Utils.loadFile(file, callback, 8192);
+    },
+
+    loadFile: function(file, callback, maxSize) {
+       maxSize = maxSize || 32 * 1024;
+       if (file.size > maxSize) {
+           Ext.Msg.alert(gettext('Error'), `${gettext("Invalid file size")}: ${file.size} > ${maxSize}`);
            return;
        }
        let reader = new FileReader();
-       reader.onload = function(evt) {
-           callback(evt.target.result);
-       };
+       reader.onload = evt => callback(evt.target.result);
        reader.readAsText(file);
     },