From 64205cf8f2f7962e23becee89377599a14697086 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 28 Sep 2026 07:04:21 +0800 Subject: [PATCH] fix: remove legacy cloud image import restriction --- engine/static/app.js | 12 ++++++++--- engine/static/index.html | 4 ++-- engine/tests/test_template_frontend.py | 28 ++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/engine/static/app.js b/engine/static/app.js index 6f344ed7..6ad39396 100644 --- a/engine/static/app.js +++ b/engine/static/app.js @@ -3523,9 +3523,15 @@ byId("template-import-form").addEventListener("submit", async (event) => { showError("template-import-error", "请填写不超过 64 个字符的模板名称。"); return; } - if (!existingJobId && (!url || url.origin !== "https://repo.almalinux.org" || url.username || url.password || url.search || url.hash - || !/^\/almalinux\/(9|10)\/cloud\/x86_64\/images\/AlmaLinux-\1-GenericCloud-[A-Za-z0-9._-]+\.x86_64\.qcow2$/.test(url.pathname))) { - showError("template-import-error", "目前仅支持 repo.almalinux.org 上的 AlmaLinux 9 / 10 x86_64 GenericCloud qcow2 HTTPS 地址。"); + const officialHosts = new Set([ + "repo.almalinux.org", + "cloud.debian.org", + "cloud-images.ubuntu.com", + "cloud.centos.org", + ]); + if (!existingJobId && (!url || url.protocol !== "https:" || !officialHosts.has(url.hostname) + || (url.port && url.port !== "443") || url.username || url.password || url.search || url.hash)) { + showError("template-import-error", "请填写受支持发行版官方镜像站的 HTTPS 文件地址。"); return; } if (!existingJobId && sha256 && !/^[a-f0-9]{64}$/.test(sha256)) { diff --git a/engine/static/index.html b/engine/static/index.html index 93e64fca..3f611b3a 100644 --- a/engine/static/index.html +++ b/engine/static/index.html @@ -391,10 +391,10 @@
CLOUD IMAGE CATALOG

云镜像模板

仅管理员可以导入官方云镜像和修改模板名称;用户创建虚拟机时选择已导入的版本。

-
+

导入云镜像

从 AlmaLinux 官方仓库下载;可选择使用发布方 SHA-256 校验。

+
+

导入云镜像

从受支持发行版的官方镜像站下载;可选择使用发布方 SHA-256 校验。

- 支持 repo.almalinux.org 的 AlmaLinux 9 / 10 x86_64 GenericCloud qcow2 镜像。 + 支持 AlmaLinux 8/9/10、Debian 11/12/13、CentOS Stream 9/10 和 Ubuntu 20.04/22.04/24.04/25.04/25.10/26.04 官方 x86_64 云镜像;Ubuntu 官方 qcow2 内容的 .img 文件也可导入。 留空时面板仍会计算并保存实际 SHA-256;填写后会在导入前核对。
diff --git a/engine/tests/test_template_frontend.py b/engine/tests/test_template_frontend.py index 83d7338e..8ea52790 100644 --- a/engine/tests/test_template_frontend.py +++ b/engine/tests/test_template_frontend.py @@ -180,6 +180,34 @@ def test_system_family_metadata_recognizes_debian_centos_and_ubuntu() -> None: assert "/^[0-9]+(?:\\.[0-9]+)?$/" in system_code +def test_template_import_form_accepts_every_supported_official_host() -> None: + script = (STATIC / "app.js").read_text(encoding="utf-8") + submit_code = script.split( + 'byId("template-import-form").addEventListener("submit"', 1 + )[1].split('byId("rescue-template-form")', 1)[0] + for hostname in ( + "repo.almalinux.org", + "cloud.debian.org", + "cloud-images.ubuntu.com", + "cloud.centos.org", + ): + assert f'"{hostname}"' in submit_code + assert 'url.protocol !== "https:"' in submit_code + assert 'url.port !== "443"' in submit_code + assert "url.username" in submit_code and "url.password" in submit_code + assert "url.search" in submit_code and "url.hash" in submit_code + assert "/almalinux\\/(9|10)" not in submit_code + + page = (STATIC / "index.html").read_text(encoding="utf-8") + for label in ( + "AlmaLinux 8/9/10", + "Debian 11/12/13", + "CentOS Stream 9/10", + "Ubuntu 20.04/22.04/24.04/25.04/25.10/26.04", + ): + assert label in page + + def test_version_cards_show_only_centered_template_name() -> None: script = (STATIC / "app.js").read_text(encoding="utf-8") catalog_code = script.split("function renderTemplateCatalog(inputId) {", 1)[1].split(