]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/window/DownloadUrlToStorage.js
ui: avoid trivial decompression widget, only used once
[pve-manager.git] / www / manager6 / window / DownloadUrlToStorage.js
CommitLineData
01366f9e
TL
1Ext.define('PVE.window.DownloadUrlToStorage', {
2 extend: 'Proxmox.window.Edit',
3 alias: 'widget.pveStorageDownloadUrl',
4 mixins: ['Proxmox.Mixin.CBind'],
5
6 isCreate: true,
7
8 method: 'POST',
9
10 showTaskViewer: true,
11
12 title: gettext('Download from URL'),
13 submitText: gettext('Download'),
14
15 cbindData: function(initialConfig) {
16 var me = this;
17 return {
18 nodename: me.nodename,
19 storage: me.storage,
20 content: me.content,
21 };
22 },
23
24 cbind: {
25 url: '/nodes/{nodename}/storage/{storage}/download-url',
26 },
27
9ebd97fe
TL
28
29 viewModel: {
30 data: {
a2692d6b
TL
31 size: '-',
32 mimetype: '-',
9ebd97fe
TL
33 enableQuery: true,
34 },
a2692d6b
TL
35 },
36
01366f9e
TL
37 controller: {
38 xclass: 'Ext.app.ViewController',
39
40 urlChange: function(field) {
9ebd97fe
TL
41 this.resetMetaInfo();
42 this.setQueryEnabled();
43 },
44 setQueryEnabled: function() {
45 this.getViewModel().set('enableQuery', true);
46 },
47 resetMetaInfo: function() {
48 let vm = this.getViewModel();
49 vm.set('size', '-');
50 vm.set('mimetype', '-');
01366f9e
TL
51 },
52
53 urlCheck: function(field) {
54 let me = this;
55 let view = me.getView();
a2692d6b
TL
56
57 const queryParam = view.getValues();
58
9ebd97fe
TL
59 me.getViewModel().set('enableQuery', false);
60 me.resetMetaInfo();
a2692d6b
TL
61 let urlField = view.down('[name=url]');
62
01366f9e
TL
63 Proxmox.Utils.API2Request({
64 url: `/nodes/${view.nodename}/query-url-metadata`,
65 method: 'GET',
66 params: {
a2692d6b
TL
67 url: queryParam.url,
68 'verify-certificates': queryParam['verify-certificates'],
e86862bf 69 'detect-compression': view.content === 'iso' ? 1 : 0,
01366f9e
TL
70 },
71 waitMsgTarget: view,
a2692d6b
TL
72 failure: res => {
73 urlField.setValidation(res.result.message);
74 urlField.validate();
75 Ext.MessageBox.alert(gettext('Error'), res.htmlStatus);
9ebd97fe
TL
76 // re-enable so one can directly requery, e.g., if it was just a network hiccup
77 me.setQueryEnabled();
01366f9e
TL
78 },
79 success: function(res, opt) {
a2692d6b
TL
80 urlField.setValidation();
81 urlField.validate();
01366f9e
TL
82
83 let data = res.result.data;
84 view.setValues({
85 filename: data.filename || "",
a2692d6b
TL
86 size: (data.size && Proxmox.Utils.format_size(data.size)) || gettext("Unknown"),
87 mimetype: data.mimetype || gettext("Unknown"),
e86862bf 88 compression: data.compression || '__default__',
01366f9e
TL
89 });
90 },
91 });
92 },
93
94 hashChange: function(field) {
95 let checksum = Ext.getCmp('downloadUrlChecksum');
96 if (field.getValue() === '__default__') {
97 checksum.setDisabled(true);
98 checksum.setValue("");
99 checksum.allowBlank = true;
100 } else {
101 checksum.setDisabled(false);
102 checksum.allowBlank = false;
103 }
104 },
105 },
106
107 items: [
108 {
109 xtype: 'inputpanel',
110 border: false,
1ec18d40
TL
111 onGetValues: function(values) {
112 if (typeof values.checksum === 'string') {
113 values.checksum = values.checksum.trim();
114 }
115 return values;
116 },
01366f9e
TL
117 columnT: [
118 {
119 xtype: 'fieldcontainer',
120 layout: 'hbox',
121 fieldLabel: gettext('URL'),
122 items: [
123 {
124 xtype: 'textfield',
125 name: 'url',
a2692d6b 126 emptyText: gettext("Enter URL to download"),
01366f9e
TL
127 allowBlank: false,
128 flex: 1,
129 listeners: {
130 change: 'urlChange',
131 },
132 },
133 {
134 xtype: 'button',
135 name: 'check',
a2692d6b 136 text: gettext('Query URL'),
01366f9e 137 margin: '0 0 0 5',
9ebd97fe
TL
138 bind: {
139 disabled: '{!enableQuery}',
140 },
01366f9e
TL
141 listeners: {
142 click: 'urlCheck',
143 },
144 },
145 ],
146 },
147 {
148 xtype: 'textfield',
149 name: 'filename',
150 allowBlank: false,
151 fieldLabel: gettext('File name'),
a2692d6b 152 emptyText: gettext("Please (re-)query URL to get meta information"),
01366f9e
TL
153 },
154 ],
155 column1: [
156 {
157 xtype: 'displayfield',
158 name: 'size',
159 fieldLabel: gettext('File size'),
9ebd97fe
TL
160 bind: {
161 value: '{size}',
162 },
01366f9e
TL
163 },
164 ],
165 column2: [
166 {
167 xtype: 'displayfield',
168 name: 'mimetype',
169 fieldLabel: gettext('MIME type'),
9ebd97fe
TL
170 bind: {
171 value: '{mimetype}',
172 },
01366f9e
TL
173 },
174 ],
175 advancedColumn1: [
176 {
177 xtype: 'pveHashAlgorithmSelector',
178 name: 'checksum-algorithm',
179 fieldLabel: gettext('Hash algorithm'),
180 allowBlank: true,
181 hasNoneOption: true,
182 value: '__default__',
183 listeners: {
184 change: 'hashChange',
185 },
186 },
187 {
188 xtype: 'textfield',
189 name: 'checksum',
190 fieldLabel: gettext('Checksum'),
191 allowBlank: true,
192 disabled: true,
193 emptyText: gettext('none'),
194 id: 'downloadUrlChecksum',
195 },
196 ],
197 advancedColumn2: [
198 {
199 xtype: 'proxmoxcheckbox',
200 name: 'verify-certificates',
201 fieldLabel: gettext('Verify certificates'),
202 uncheckedValue: 0,
203 checked: true,
204 listeners: {
5a963750 205 change: 'setQueryEnabled',
01366f9e
TL
206 },
207 },
e86862bf 208 {
65704cc2 209 xtype: 'proxmoxKVComboBox',
e86862bf
PH
210 name: 'compression',
211 fieldLabel: gettext('Decompression algorithm'),
212 allowBlank: true,
213 hasNoneOption: true,
65704cc2 214 deleteEmpty: false,
e86862bf 215 value: '__default__',
65704cc2
TL
216 comboItems: [
217 ['__default__', Proxmox.Utils.NoneText],
218 ['lzo', 'LZO'],
219 ['gz', 'GZIP'],
220 ['zst', 'ZSTD'],
221 ],
e86862bf
PH
222 cbind: {
223 hidden: get => get('content') !== 'iso',
224 },
225 },
01366f9e
TL
226 ],
227 },
228 {
229 xtype: 'hiddenfield',
230 name: 'content',
231 cbind: {
232 value: '{content}',
233 },
234 },
235 ],
236
237 initComponent: function() {
58ab77d1 238 var me = this;
01366f9e
TL
239
240 if (!me.nodename) {
241 throw "no node name specified";
242 }
243 if (!me.storage) {
244 throw "no storage ID specified";
245 }
58ab77d1 246 me.callParent();
01366f9e
TL
247 },
248});
249