[pve-devel] [PATCH pve-manager 1/1] fix #4849: download to storage: automatically detect and configure compression
Philipp Hufnagl
p.hufnagl at proxmox.com
Tue Jul 25 16:37:20 CEST 2023
Signed-off-by: Philipp Hufnagl <p.hufnagl at proxmox.com>
---
PVE/API2/Nodes.pm | 21 ++++++++++++++++-
www/manager6/Makefile | 1 +
www/manager6/form/DecompressionSelector.js | 14 +++++++++++
www/manager6/window/DownloadUrlToStorage.js | 26 +++++++++++++++++++--
4 files changed, 59 insertions(+), 3 deletions(-)
create mode 100644 www/manager6/form/DecompressionSelector.js
diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index 9269694d..de16d9a6 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -1564,6 +1564,12 @@ __PACKAGE__->register_method({
type => 'boolean',
optional => 1,
default => 1,
+ },
+ 'find-compression' => {
+ description => "If true an auto detuction of used compression will be attempted",
+ type => 'boolean',
+ optional => 1,
+ default => 0,
}
},
},
@@ -1583,6 +1589,10 @@ __PACKAGE__->register_method({
type => 'string',
optional => 1,
},
+ compression => {
+ type => 'string',
+ optional => 1,
+ },
},
},
code => sub {
@@ -1606,6 +1616,8 @@ __PACKAGE__->register_method({
);
}
+ my $find_compression = $param->{'find-compression'};
+
my $req = HTTP::Request->new(HEAD => $url);
my $res = $ua->request($req);
@@ -1614,7 +1626,7 @@ __PACKAGE__->register_method({
my $size = $res->header("Content-Length");
my $disposition = $res->header("Content-Disposition");
my $type = $res->header("Content-Type");
-
+ my $compression = "__default__";
my $filename;
if ($disposition && ($disposition =~ m/filename="([^"]*)"/ || $disposition =~ m/filename=([^;]*)/)) {
@@ -1628,10 +1640,17 @@ __PACKAGE__->register_method({
$type = $1;
}
+ if($find_compression && $filename && $filename =~ m!((^.+)(?:\.(${\PVE::Storage::Plugin::COMPRESSOR_RE})))$! && $3)
+ {
+ $filename = $2 ;
+ $compression = "$3";
+ }
+
my $ret = {};
$ret->{filename} = $filename if $filename;
$ret->{size} = $size + 0 if $size;
$ret->{mimetype} = $type if $type;
+ $ret->{compression} = $compression if $compression;
return $ret;
}});
diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index 7ec9d7a5..42a27548 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -34,6 +34,7 @@ JSSRC= \
form/ContentTypeSelector.js \
form/ControllerSelector.js \
form/DayOfWeekSelector.js \
+ form/DecompressionSelector.js \
form/DiskFormatSelector.js \
form/DiskStorageSelector.js \
form/EmailNotificationSelector.js \
diff --git a/www/manager6/form/DecompressionSelector.js b/www/manager6/form/DecompressionSelector.js
new file mode 100644
index 00000000..35d8d738
--- /dev/null
+++ b/www/manager6/form/DecompressionSelector.js
@@ -0,0 +1,14 @@
+
+Ext.define('PVE.form.DecompressionSelector', {
+ extend: 'Proxmox.form.KVComboBox',
+ alias: ['widget.pveDecompressionSelector'],
+ config: {
+ deleteEmpty: false,
+ },
+ comboItems: [
+ ['__default__', 'None'],
+ ['lzo', 'LZO'],
+ ['gz', 'GZIP'],
+ ['zst', 'ZSTD'],
+ ],
+});
\ No newline at end of file
diff --git a/www/manager6/window/DownloadUrlToStorage.js b/www/manager6/window/DownloadUrlToStorage.js
index 48543d28..b40b7ea6 100644
--- a/www/manager6/window/DownloadUrlToStorage.js
+++ b/www/manager6/window/DownloadUrlToStorage.js
@@ -49,6 +49,9 @@ Ext.define('PVE.window.DownloadUrlToStorage', {
vm.set('size', '-');
vm.set('mimetype', '-');
},
+ decompressonPossible: function() {
+ return this.view.content === 'iso';
+ },
urlCheck: function(field) {
let me = this;
@@ -66,6 +69,7 @@ Ext.define('PVE.window.DownloadUrlToStorage', {
params: {
url: queryParam.url,
'verify-certificates': queryParam['verify-certificates'],
+ 'find-compression': me.decompressonPossible() ? 1 : 0 ,
},
waitMsgTarget: view,
failure: res => {
@@ -84,6 +88,7 @@ Ext.define('PVE.window.DownloadUrlToStorage', {
filename: data.filename || "",
size: (data.size && Proxmox.Utils.format_size(data.size)) || gettext("Unknown"),
mimetype: data.mimetype || gettext("Unknown"),
+ compression: data.compression || '__default__',
});
},
});
@@ -215,7 +220,7 @@ Ext.define('PVE.window.DownloadUrlToStorage', {
],
initComponent: function() {
- var me = this;
+ var me = this;
if (!me.nodename) {
throw "no node name specified";
@@ -223,8 +228,25 @@ Ext.define('PVE.window.DownloadUrlToStorage', {
if (!me.storage) {
throw "no storage ID specified";
}
+ if(me.content === 'iso')
+ {
+ me.items[0].advancedColumn2.push(
+
+ {
+ xtype: 'pveDecompressionSelector',
+ name: 'compression',
+ fieldLabel: gettext('Decompression algorithm'),
+ allowBlank: true,
+ hasNoneOption: true,
+ value: '__default__',
+ listeners: {
+ change: 'decryptorChange',
+ },
+ });
+
+ }
- me.callParent();
+ me.callParent();
},
});
--
2.39.2
More information about the pve-devel
mailing list