Skip to content

Commit 552db1a

Browse files
committed
perf: 优化获取节点列表时的检查和报错提示
1 parent b1b0bb1 commit 552db1a

3 files changed

Lines changed: 33 additions & 6 deletions

File tree

Script/Script.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,17 @@ function main(config) {
336336

337337
// 获取节点列表
338338
const proxies = config.proxies || [];
339-
if (!proxies.length) {
340-
throw new Error('配置文件中未找到任何节点');
339+
340+
// 验证节点列表是否存在代理节点
341+
const allDirectOrReject = proxies.every((p) => {
342+
const type = p.type?.toLowerCase();
343+
return type === 'direct' || type === 'reject';
344+
});
345+
346+
if (!proxies.length || allDirectOrReject) {
347+
throw new Error(
348+
'配置文件中未找到任何代理节点,请使用机场提供的配置文件进行覆写',
349+
);
341350
}
342351

343352
// --- 构建地区组和倍率组 ---

Script/mihomoScript.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,17 @@ function main(config) {
608608

609609
// 获取节点列表
610610
const proxies = config.proxies || [];
611-
if (!proxies.length) {
612-
throw new Error('配置文件中未找到任何节点');
611+
612+
// 验证节点列表是否存在代理节点
613+
const allDirectOrReject = proxies.every((p) => {
614+
const type = p.type?.toLowerCase();
615+
return type === 'direct' || type === 'reject';
616+
});
617+
618+
if (!proxies.length || allDirectOrReject) {
619+
throw new Error(
620+
'配置文件中未找到任何代理节点,请使用机场提供的配置文件进行覆写',
621+
);
613622
}
614623

615624
// --- 构建地区组和倍率组 ---

src/config/main.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,17 @@ function main(config) {
3030

3131
// 获取节点列表
3232
const proxies = config.proxies || [];
33-
if (!proxies.length) {
34-
throw new Error('配置文件中未找到任何节点');
33+
34+
// 验证节点列表是否存在代理节点
35+
const allDirectOrReject = proxies.every((p) => {
36+
const type = p.type?.toLowerCase();
37+
return type === 'direct' || type === 'reject';
38+
});
39+
40+
if (!proxies.length || allDirectOrReject) {
41+
throw new Error(
42+
'配置文件中未找到任何代理节点,请使用机场提供的配置文件进行覆写',
43+
);
3544
}
3645

3746
// --- 构建地区组和倍率组 ---

0 commit comments

Comments
 (0)