ui: utils: split out general "load local file" helper

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-05-19 11:07:03 +02:00
parent 48bbb009c3
commit 37f2e82ca2

View 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);
},