Files
cieanyau 651c36367f
前端验证 / verify (push) Failing after 15m2s
接入 ESLint 与 Prettier 并加入 CI 静态门禁
2026-11-07 01:24:36 +08:00

82 lines
2.9 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** 镜像名称展示清理:统一系统品牌/版本分隔,移除文件扩展名和冗余的 64 位标记。 */
var e = {
debian: `Debian`,
ubuntu: `Ubuntu`,
centos: `CentOS`,
windows: `Windows`,
rocky: `Rocky`,
"rocky linux": `Rocky Linux`,
almalinux: `AlmaLinux`,
fedora: `Fedora`,
openeuler: `openEuler`,
freebsd: `FreeBSD`,
tencentos: `TencentOS`,
alpine: `Alpine`,
"alpine linux": `Alpine Linux`,
},
t = {
server: `Server`,
stream: `Stream`,
datacenter: `Datacenter`,
standard: `Standard`,
enterprise: `Enterprise`,
professional: `Professional`,
essentials: `Essentials`,
education: `Education`,
desktop: `Desktop`,
minimal: `Minimal`,
core: `Core`,
pro: `Pro`,
home: `Home`,
lts: `LTS`,
uefi: `UEFI`,
bios: `BIOS`,
gpt: `GPT`,
bt: `BT`,
};
// 仅改写已知系统前缀及可识别的版本词;不认识的尾部原样保留,避免丢失镜像特征。
function n(n) {
let r = n.match(
/^(Debian|Ubuntu|CentOS|Windows|Rocky(?:[ _-]+Linux)?|AlmaLinux|Fedora|openEuler|FreeBSD|TencentOS|Alpine(?:[ _-]+Linux)?)(?=$|[\d\s_-])/i,
);
if (!r) return n;
let i = n.slice(r[0].length),
a = !1,
o = [e[r[0].replace(/[ _-]+/g, ` `).toLowerCase()]],
s =
/^[\s_-]*(x86[_-]64|64[ _-]?(?:bits?|位)|32[ _-]?(?:bits?|位)|\d+(?:\.\d+)*(?:R2)?|Server|Stream|Datacenter|Standard|Enterprise|Professional|Essentials|Education|Desktop|Minimal|Core|Pro|Home|R2|LTS|SP\d+|UEFI|BIOS|GPT|BT|ARM64|aarch64|x64|amd64|x86|x32|i386|i686|ARM|cn|en|zh(?:[ _-](?:CN|TW))?|专业版|标准版|数据中心版|企业版|家庭版|教育版|中文版|英文版)(?=$|[\s_()()[\]【】-])/i;
for (let e = i.match(s); e; e = i.match(s)) {
let n = t[e[1].toLowerCase()] ?? e[1];
(/^\d+(?:\.\d+)*(?:R2)?$/i.test(n) &&
(o[0] === `CentOS` &&
!a &&
(n = n.replace(/^(\d+\.\d+)(?:\.\d+)+$/, `$1`)),
(n = n.replace(/^(\d+(?:\.\d+)*)R2$/i, `$1 R2`)),
(a = !0)),
o.push(n),
(i = i.slice(e[0].length)));
}
return o.join(` `) + i;
}
// 这是显示名称处理,不改变实际镜像 id;完全为空的优化版名称显示“默认镜像”。
function r(e) {
if (typeof e != `string`) return ``;
let t = e.trim();
if (!t) return ``;
let r = `(?:x86[_-]64|x64|amd64|64[ _-]?(?:bit|bits|位))`;
return (
n(t.replace(/\.(?:iso|qcow2?|img|raw|vhdx?|vmdk)$/i, ``))
.replace(
/[\s_-]*(?:[((【[]\s*)?纯净优化版(?:\s*[))】\]])?(?=$|[\s_-])/g,
``,
)
.replace(RegExp(`[((\\[【]\\s*${r}\\s*[))\\]】]`, `gi`), ` `)
.replace(RegExp(`(^|[\\s_])${r}(?=$|[\\s_])`, `gi`), `$1`)
.replace(RegExp(`-${r}$`, `i`), ``)
.replace(/_+/g, ` `)
.replace(/\s+/g, ` `)
.trim() || (t.includes(`纯净优化版`) ? `默认镜像` : t)
);
}
export { r as t };