From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 8386E61AAD for ; Wed, 26 Jul 2023 14:31:37 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6D67E6268 for ; Wed, 26 Jul 2023 14:31:37 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 26 Jul 2023 14:31:36 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 781824538F for ; Wed, 26 Jul 2023 14:31:36 +0200 (CEST) Date: Wed, 26 Jul 2023 14:31:28 +0200 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20230725143720.620577-1-p.hufnagl@proxmox.com> <20230725143720.620577-4-p.hufnagl@proxmox.com> In-Reply-To: <20230725143720.620577-4-p.hufnagl@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.16.0 (https://github.com/astroidmail/astroid) Message-Id: <1690370269.xmujv9chwd.astroid@yuna.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.070 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: Re: [pve-devel] [PATCH pve-manager 1/1] fix #4849: download to storage: automatically detect and configure compression X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Jul 2023 12:31:37 -0000 On July 25, 2023 4:37 pm, Philipp Hufnagl wrote: > Signed-off-by: Philipp Hufnagl > --- > 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 >=20 > 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 =3D> 'boolean', > optional =3D> 1, > default =3D> 1, > + }, > + 'find-compression' =3D> { > + description =3D> "If true an auto detuction of used compression will b= e attempted", typo ;) detect might be better naming than find > + type =3D> 'boolean', > + optional =3D> 1, > + default =3D> 0, > } > }, > }, > @@ -1583,6 +1589,10 @@ __PACKAGE__->register_method({ > type =3D> 'string', > optional =3D> 1, > }, > + compression =3D> { > + type =3D> 'string', could get the same enum annotation that the parameter in pve-storage should get - but if it is included here, it should probably be defined once in pve-storage, so that updates there don't need to be duplicated here as well.. > + optional =3D> 1, > + }, > }, > }, > code =3D> sub { > @@ -1606,6 +1616,8 @@ __PACKAGE__->register_method({ > ); > } > =20 > + my $find_compression =3D $param->{'find-compression'}; > + > my $req =3D HTTP::Request->new(HEAD =3D> $url); > my $res =3D $ua->request($req); > =20 > @@ -1614,7 +1626,7 @@ __PACKAGE__->register_method({ > my $size =3D $res->header("Content-Length"); > my $disposition =3D $res->header("Content-Disposition"); > my $type =3D $res->header("Content-Type"); > - > + my $compression =3D "__default__"; this is wrong, there cannot be a default compression that is detected (and if there were, it shouldn't be the placeholder special value used in the GUI!) > my $filename; > =20 > if ($disposition && ($disposition =3D~ m/filename=3D"([^"]*)"/ || $disp= osition =3D~ m/filename=3D([^;]*)/)) { > @@ -1628,10 +1640,17 @@ __PACKAGE__->register_method({ > $type =3D $1; > } > =20 > + if($find_compression && $filename && $filename =3D~ m!((^.+)(?:\= .(${\PVE::Storage::Plugin::COMPRESSOR_RE})))$! && $3) style! missing space after if, and way too long condition.. the non-capturing group and the outermost capturing one can be dropped AFAI= CT, just=20 m!(^.+)\.(${\PVE::Storage::Plugin::COMPRESSOR_RE})$! would be fine grouping wise. but the RE is still wrong, it should be properly anchored (I am not sure whether the first group was an attempt to anchor, or an attempt to exclude the '.' character?). probably what you meant was something like m!^(.+)\.(${\PVE::Storage::Plugin::COMPRESSOR_RE})$! but, please double check :) the last part of the condition can also be dropped, since if the RE matched, $3 must be defined. the RE could be moved into a variable > + { style! > + $filename =3D $2 ; > + $compression =3D "$3"; indentation, and whitespace sneaking in ;) also, why is one captured group quoted and the other not? > + } > + > my $ret =3D {}; > $ret->{filename} =3D $filename if $filename; > $ret->{size} =3D $size + 0 if $size; > $ret->{mimetype} =3D $type if $type; > + $ret->{compression} =3D $compression if $compression; > =20 > 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=3D \ > 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/fo= rm/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'], there is a Proxmox.Utils.noneText (which just wraps `gettext('None')`). > + ['lzo', 'LZO'], > + ['gz', 'GZIP'], > + ['zst', 'ZSTD'], > + ], > +}); > \ No newline at end of file ? eslint is also unhappy: [./form/DecompressionSelector.js]: WARN: line 14 col 4: eol-last - Newline required at end of file but not fou= nd. (*) > diff --git a/www/manager6/window/DownloadUrlToStorage.js b/www/manager6/w= indow/DownloadUrlToStorage.js > index 48543d28..b40b7ea6 100644 > --- a/www/manager6/window/DownloadUrlToStorage.js > +++ b/www/manager6/window/DownloadUrlToStorage.js [./window/DownloadUrlToStorage.js]: WARN: line 72 col 61: comma-spacing - There should be no space before ','. = (*) WARN: line 231 col 2: keyword-spacing - Expected space(s) after "if". (*) WARN: line 232 col 2: brace-style - Opening curly brace does not appear on = the same line as controlling statement. (*) WARN: line 245 col 6: padded-blocks - Block must not be padded by blank lin= es. (*) please make these eslint warnings happy.. > @@ -49,6 +49,9 @@ Ext.define('PVE.window.DownloadUrlToStorage', { > vm.set('size', '-'); > vm.set('mimetype', '-'); > }, > + decompressonPossible: function() { typo in function name > + return this.view.content =3D=3D=3D 'iso'; > + }, > =20 > urlCheck: function(field) { > let me =3D 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 =3D> { > @@ -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', { > ], > =20 > initComponent: function() { > - var me =3D this; > + var me =3D this; > =20 > 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 =3D=3D=3D 'iso') > + { > + me.items[0].advancedColumn2.push( > + > + { > + xtype: 'pveDecompressionSelector', > + name: 'compression', > + fieldLabel: gettext('Decompression algorithm'), > + allowBlank: true, > + hasNoneOption: true, > + value: '__default__', > + listeners: { > + change: 'decryptorChange', decryptorChange is not defined anywhere > + }, > + }); > + > + } > =20 > - me.callParent(); > + me.callParent(); > }, > }); > =20 > --=20 > 2.39.2 >=20 >=20 >=20 > _______________________________________________ > pve-devel mailing list > pve-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >=20 >=20 >=20