public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager v5 1/3] ui: storage content: allow upload of guest images for import type
Date: Tue,  1 Apr 2025 10:23:16 +0200	[thread overview]
Message-ID: <20250401082318.1312661-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20250401082318.1312661-1-d.csapak@proxmox.com>

by allowing 'qcow2', 'vmdk', 'raw' and 'img' files to upload.

Implement 'extension aliases' for the upload window, that append the
'real' extension to the filename after selecting a file with such an
alias. This is necessary so that we have seperate lists for the file
selector and the filename validator. Use that to mark '.img' an alias of
'.raw' for import.

For the download, the api checks the filename for us first, so we
just have to rename '.img' to '.img.raw'.

partially fixes #2424

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
changes from v4:
* add generic extension alias mechanism instead of hardcodig behavior
  for '.img', and have seperate validation for file selector and the
  file name field

 www/manager6/window/DownloadUrlToStorage.js |  4 ++++
 www/manager6/window/UploadToStorage.js      | 24 +++++++++++++++++----
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/www/manager6/window/DownloadUrlToStorage.js b/www/manager6/window/DownloadUrlToStorage.js
index 3ac80ac9..aabc9d3c 100644
--- a/www/manager6/window/DownloadUrlToStorage.js
+++ b/www/manager6/window/DownloadUrlToStorage.js
@@ -89,6 +89,10 @@ Ext.define('PVE.window.DownloadUrlToStorage', {
 			    filename = matches[1];
 			    compression = matches[2].toLowerCase();
 			}
+		    } else if (view.content === 'import') {
+			if (filename.endsWith('.img')) {
+			    filename += '.raw';
+			}
 		    }
 
 		    view.setValues({
diff --git a/www/manager6/window/UploadToStorage.js b/www/manager6/window/UploadToStorage.js
index cdf548a8..f29d80f4 100644
--- a/www/manager6/window/UploadToStorage.js
+++ b/www/manager6/window/UploadToStorage.js
@@ -9,19 +9,28 @@ Ext.define('PVE.window.UploadToStorage', {
     title: gettext('Upload'),
 
     acceptedExtensions: {
-	'import': ['.ova'],
+	'import': ['.ova', '.qcow2', '.raw', '.vmdk'],
 	iso: ['.img', '.iso'],
 	vztmpl: ['.tar.gz', '.tar.xz', '.tar.zst'],
     },
 
+    // accepted for file selection, will be renamed to real extension
+    extensionAliases: {
+	'import': {
+	    '.img': '.raw',
+	},
+    },
+
     cbindData: function(initialConfig) {
 	const me = this;
 	const ext = me.acceptedExtensions[me.content] || [];
 
 	me.url = `/nodes/${me.nodename}/storage/${me.storage}/upload`;
 
+	let fileSelectorExt = ext.concat(Object.keys(me.extensionAliases[me.content] ?? {}));
+
 	return {
-	    extensions: ext.join(', '),
+	    extensions: fileSelectorExt.join(', '),
 	    filenameRegex: RegExp('^.*(?:' + ext.join('|').replaceAll('.', '\\.') + ')$', 'i'),
 	};
     },
@@ -134,8 +143,15 @@ Ext.define('PVE.window.UploadToStorage', {
 	},
 
 	fileChange: function(input) {
-	    const vm = this.getViewModel();
-	    const name = input.value.replace(/^.*(\/|\\)/, '');
+	    const me = this;
+	    const vm = me.getViewModel();
+	    const view = me.getView();
+	    let name = input.value.replace(/^.*(\/|\\)/, '');
+	    for (const [alias, real] of Object.entries(view.extensionAliases[view.content] ?? {})) {
+		if (name.endsWith(alias)) {
+		    name += real;
+		}
+	    }
 	    const fileInput = input.fileInputEl.dom;
 	    vm.set('filename', name);
 	    vm.set('size', (fileInput.files[0] && Proxmox.Utils.format_size(fileInput.files[0].size)) || '-');
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  parent reply	other threads:[~2025-04-01  8:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-01  8:23 [pve-devel] [PATCH storage/manager v5] allow down/upload & import of images in the web UI Dominik Csapak
2025-04-01  8:23 ` [pve-devel] [PATCH storage v5 1/1] import: allow upload of guest images files into import storage Dominik Csapak
2025-04-04 14:11   ` Fiona Ebner
2025-04-07  9:44     ` Thomas Lamprecht
2025-04-01  8:23 ` Dominik Csapak [this message]
2025-04-01  8:23 ` [pve-devel] [PATCH manager v5 2/3] ui: form: file selector: allow optional filter Dominik Csapak
2025-04-01  8:23 ` [pve-devel] [PATCH manager v5 3/3] ui: qemu hd edit: allow importing a disk from the import storage Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250401082318.1312661-3-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal