mirror of
https://git.proxmox.com/git/pve-manager
synced 2025-07-25 20:05:21 +00:00
ui: utils: split out general "load local file" helper
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
48bbb009c3
commit
37f2e82ca2
@ -1500,18 +1500,19 @@ Ext.define('PVE.Utils', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
loadSSHKeyFromFile: function(file, callback) {
|
loadSSHKeyFromFile: function(file, callback) {
|
||||||
// ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
|
// ssh-keygen produces ~ 740 bytes for a 4096 bit RSA key, current max is 16 kbit, so assume:
|
||||||
// a user@host comment, 1420 for 8192 bits; current max is 16kbit
|
// 740 * 8 for max. 32kbit (5920 bytes), round upwards to 8192 bytes, leaves lots of comment space
|
||||||
// assume: 740*8 for max. 32kbit (5920 byte file)
|
PVE.Utils.loadFile(file, callback, 8192);
|
||||||
// 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);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
let reader = new FileReader();
|
let reader = new FileReader();
|
||||||
reader.onload = function(evt) {
|
reader.onload = evt => callback(evt.target.result);
|
||||||
callback(evt.target.result);
|
|
||||||
};
|
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user