Skip to content

Commit

Permalink
feat: getNodeNames 和 getClashNodeNames 不再过滤 nodeType
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Oct 27, 2019
1 parent 67c9a99 commit 6571511
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 28 deletions.
8 changes: 4 additions & 4 deletions examples/quantumultx/template/quantumultx.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ server=119.29.29.29
{{ getDownloadUrl('Quantumult_subscribe_hk.conf') }}, tag=🇭🇰 HK

[policy]
available=🇺🇸 Auto US, {{ getNodeNames(nodeList, ['shadowsocks'], usFilter) }}
available=🇭🇰 Auto HK, {{ getNodeNames(nodeList, ['shadowsocks'], hkFilter) }}
static=Netflix, PROXY, {{ getNodeNames(nodeList, ['shadowsocks'], netflixFilter) }}, img-url=https://raw.githubusercontent.com/zealson/Zure/master/IconSet/Netflix.png
static=YouTube, PROXY, {{ getNodeNames(nodeList, ['shadowsocks'], youtubePremiumFilter) }}, img-url=https://raw.githubusercontent.com/zealson/Zure/master/IconSet/YouTube.png
available=🇺🇸 Auto US, {{ getNodeNames(nodeList, usFilter) }}
available=🇭🇰 Auto HK, {{ getNodeNames(nodeList, hkFilter) }}
static=Netflix, PROXY, {{ getNodeNames(nodeList, netflixFilter) }}, img-url=https://raw.githubusercontent.com/zealson/Zure/master/IconSet/Netflix.png
static=YouTube, PROXY, {{ getNodeNames(nodeList, youtubePremiumFilter) }}, img-url=https://raw.githubusercontent.com/zealson/Zure/master/IconSet/YouTube.png
static=Apple, DIRECT, 🇺🇸 Auto US, 🇭🇰 Auto HK, img-url=https://raw.githubusercontent.com/zealson/Zure/master/IconSet/Apple.png
static=Apple CDN, DIRECT, Apple, img-url=https://raw.githubusercontent.com/zealson/Zure/master/IconSet/Apple.png
static=Paypal, DIRECT, 🇺🇸 Auto US, 🇭🇰 Auto HK, img-url=https://raw.githubusercontent.com/zealson/Zure/master/IconSet/PayPal.png
Expand Down
18 changes: 4 additions & 14 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,11 +777,10 @@ export const getShadowsocksNodesJSON = (list: ReadonlyArray<ShadowsocksNodeConfi

export const getNodeNames = (
list: ReadonlyArray<SimpleNodeConfig>,
nodeTypeList: readonly NodeTypeEnum[] = [NodeTypeEnum.Shadowsocks, NodeTypeEnum.HTTPS, NodeTypeEnum.Snell],
filter?: NodeNameFilterType
): string => {
const nodes = list.filter(item => {
const result = nodeTypeList.includes(item.type) && item.enable !== false;
const result = item.enable !== false;

if (filter) {
return filter(item) && result;
Expand All @@ -797,7 +796,6 @@ export const getClashNodeNames = (
ruleName: string,
ruleType: 'select' | 'url-test',
nodeNameList: ReadonlyArray<SimpleNodeConfig>,
nodeTypeList: ReadonlyArray<NodeTypeEnum> = [NodeTypeEnum.Shadowsocks, NodeTypeEnum.Shadowsocksr, NodeTypeEnum.Vmess],
filter?: NodeNameFilterType
): {
readonly type: string;
Expand All @@ -807,7 +805,7 @@ export const getClashNodeNames = (
readonly interval?: number;
} => {
const nodes = nodeNameList.filter(item => {
const result = nodeTypeList.includes(item.type) && item.enable !== false;
const result = item.enable !== false;

if (filter) {
return filter(item) && result;
Expand Down Expand Up @@ -878,19 +876,11 @@ export const normalizeClashProxyGroupConfig = (

return proxyGroup.map<any>(item => {
if (item.filter) {
return getClashNodeNames(item.name, item.type, nodeList, [
NodeTypeEnum.Shadowsocks,
NodeTypeEnum.Shadowsocksr,
NodeTypeEnum.Vmess,
], item.filter);
return getClashNodeNames(item.name, item.type, nodeList, item.filter);
} else if (item.proxies) {
return item;
} else {
return getClashNodeNames(item.name, item.type, nodeList, [
NodeTypeEnum.Shadowsocks,
NodeTypeEnum.Shadowsocksr,
NodeTypeEnum.Vmess,
]);
return getClashNodeNames(item.name, item.type, nodeList);
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/assign-local-port/template/test.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
{{ getSurgeNodes(nodeList) }}

[Proxy Group]
Proxy = select, {{ getNodeNames(nodeList, ['shadowsocks']) }}
Proxy = select, {{ getNodeNames(nodeList) }}
4 changes: 2 additions & 2 deletions test/fixture/custom-filter/template/test.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
{{ getSurgeNodes(nodeList) }}

[Proxy Group]
Proxy 1 = select, {{ getNodeNames(nodeList, ['shadowsocks'], customFilters.keywordFilter) }}
Proxy 2 = select, {{ getNodeNames(nodeList, ['shadowsocks'], customFilters.strictKeywordFilter) }}
Proxy 1 = select, {{ getNodeNames(nodeList, customFilters.keywordFilter) }}
Proxy 2 = select, {{ getNodeNames(nodeList, customFilters.strictKeywordFilter) }}
2 changes: 1 addition & 1 deletion test/fixture/not-specify-binPath/template/test.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
{{ getSurgeNodes(nodeList) }}

[Proxy Group]
Proxy = select, {{ getNodeNames(nodeList, ['shadowsocks']) }}
Proxy = select, {{ getNodeNames(nodeList) }}
2 changes: 1 addition & 1 deletion test/fixture/plain/template/test.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
{{ getSurgeNodes(nodeList) }}

[Proxy Group]
Proxy = select, {{ getNodeNames(nodeList, ['shadowsocks']) }}
Proxy = select, {{ getNodeNames(nodeList) }}
8 changes: 3 additions & 5 deletions test/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,10 @@ test('getNodeNames', async t => {
nodeName: 'Test Node 3',
}
];
const txt1 = utils.getNodeNames(nodeNameList, [NodeTypeEnum.Shadowsocks]);
const txt2 = utils.getNodeNames(nodeNameList, [NodeTypeEnum.Shadowsocks, NodeTypeEnum.Snell]);
const txt3 = utils.getNodeNames(nodeNameList, [NodeTypeEnum.Shadowsocks, NodeTypeEnum.Snell], simpleNodeConfig => simpleNodeConfig.nodeName !== 'Test Node 3');
const txt1 = utils.getNodeNames(nodeNameList);
const txt3 = utils.getNodeNames(nodeNameList, simpleNodeConfig => simpleNodeConfig.nodeName !== 'Test Node 3');

t.is(txt1, 'Test Node 1');
t.is(txt2, 'Test Node 1, Test Node 3');
t.is(txt1, 'Test Node 1, Test Node 3');
t.is(txt3, 'Test Node 1');
});

Expand Down

0 comments on commit 6571511

Please sign in to comment.