Skip to content

Commit b2b3990

Browse files
authored
clash
1 parent ba232e3 commit b2b3990

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

明文源吗

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,12 +1359,30 @@
13591359
throw new Error('没有有效的节点');
13601360
}
13611361

1362+
// 确保节点名称唯一,处理重复名称
1363+
const usedNames = new Set();
1364+
nodes.forEach((node, index) => {
1365+
let uniqueName = node.name;
1366+
// 如果名称已使用,添加服务器地址和端口来区分
1367+
if (usedNames.has(uniqueName)) {
1368+
uniqueName = `${node.name}-${node.server}:${node.port}`;
1369+
// 如果添加了服务器和端口后还是重复,添加索引
1370+
let counter = 1;
1371+
while (usedNames.has(uniqueName)) {
1372+
uniqueName = `${node.name}-${node.server}:${node.port}-${counter}`;
1373+
counter++;
1374+
}
1375+
}
1376+
usedNames.add(uniqueName);
1377+
node.uniqueName = uniqueName;
1378+
});
1379+
13621380
// 将节点转换为 YAML 格式(单行格式,匹配模板)
13631381
const nodesYaml = nodes.map(node => {
13641382
const props = [];
13651383

1366-
// 基本属性
1367-
props.push(`name: ${node.name}`);
1384+
// 基本属性,使用唯一名称(匹配模板格式,不加引号)
1385+
props.push(`name: ${node.uniqueName}`);
13681386
props.push(`server: ${node.server}`);
13691387
props.push(`port: ${node.port}`);
13701388
props.push(`type: ${node.type}`);

0 commit comments

Comments
 (0)