From 37f2e82ca28047d40cde9416c248681fa23a9617 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Wed, 19 May 2021 11:07:03 +0200 Subject: [PATCH] ui: utils: split out general "load local file" helper Signed-off-by: Thomas Lamprecht --- www/manager6/Utils.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js index e927a2fd..d9567979 100644 --- a/www/manager6/Utils.js +++ b/www/manager6/Utils.js @@ -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); },