♻️ refactor(core): 优化 substore 节点重命名与规范化逻辑

This commit is contained in:
Orion
2026-06-03 15:12:56 +08:00
parent 313e77421b
commit edb7d167c0
3 changed files with 26 additions and 61 deletions
+1 -38
View File
@@ -26,43 +26,7 @@ async function loadRenameUtils() {
async function operator(proxies) {
const utils = await loadRenameUtils();
const normalizeHyphenatedRegionFeatures = utils.normalizeHyphenatedRegionFeatures || (name => {
const hyphenatedMatch = String(name).match(/^([A-Z]{2})(?:\s+([A-Z]{3}))?-(.+)$/);
if (!hyphenatedMatch) return name;
const countryCode = hyphenatedMatch[1];
let regionCode = hyphenatedMatch[2]
? `${countryCode} ${hyphenatedMatch[2]}`
: countryCode;
const tokens = hyphenatedMatch[3].split('-').map(token => token.trim()).filter(Boolean);
if (
!hyphenatedMatch[2] &&
tokens.length >= 2 &&
/^[A-Z]{3}$/.test(tokens[0]) &&
/^\d{1,2}$/.test(tokens[1])
) {
regionCode = `${countryCode} ${tokens.shift()}`;
}
const sequenceIndex = tokens.findIndex(token => /^\d{1,2}$/.test(token));
if (sequenceIndex === -1) return name;
const sequenceNumber = tokens[sequenceIndex].padStart(2, '0');
const ingressTokens = tokens
.slice(0, sequenceIndex)
.map(token => token.toUpperCase());
const egressTokens = tokens.slice(sequenceIndex + 1);
const featureText = ingressTokens.length && egressTokens.length
? `${ingressTokens.join('-')}-${egressTokens.join('-')}`
: [...ingressTokens, ...egressTokens].join('-');
return [regionCode, sequenceNumber, featureText]
.filter(Boolean)
.join(' ')
.replace(/\s{2,}/g, ' ')
.trim();
});
const normalizeHyphenatedRegionFeatures = utils.normalizeHyphenatedRegionFeatures || (name => name);
const globalCount = Object.create(null);
const currentCount = Object.create(null);
const baseNames = new Array(proxies.length);
@@ -792,7 +756,6 @@ async function operator(proxies) {
core = core
.replace(/^([A-Z]{2})\s*(实验性|标准|高级)\s+IEPL\s+专线\s*\d+(.*)$/i, '$1 $2$3')
.replace(/搬瓦工荷兰/g, '搬瓦工')
.replace(/\s{2,}/g, ' ')
.trim();