Skip to content

Commit

Permalink
feat: 支持在 surgio.conf.js 中定义全局 customFilters
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Nov 13, 2019
1 parent 18f106f commit 1701b85
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ export async function generate(
youtubePremiumFilter = provider.youtubePremiumFilter || defaultYoutubePremiumFilter;
}
if (!customFilters) {
customFilters = provider.customFilters || {};
customFilters = {
...config.customFilters,
...provider.customFilters,
};
}

nodeConfigList.forEach(nodeConfig => {
Expand Down
3 changes: 3 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ export interface CommandConfig {
},
readonly proxyTestUrl?: string;
readonly proxyTestInterval?: number;
readonly customFilters?: {
readonly [name: string]: NodeNameFilterType;
};
}

export interface RemoteSnippetConfig {
Expand Down
1 change: 1 addition & 0 deletions lib/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const validateConfig = (userConfig: Partial<CommandConfig>): void => {
],
}),
proxyTestInterval: Joi.number(),
customFilters: Joi.object().pattern(Joi.string(), Joi.function()),
})
.unknown();

Expand Down
3 changes: 3 additions & 0 deletions test/fixture/plain/surgio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ module.exports = {
surgeConfig: {
v2ray: 'native',
},
customFilters: {
globalFilter: node => node.nodeName === '测试中文',
},
};
2 changes: 2 additions & 0 deletions test/fixture/plain/template/template-functions.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
{{ getNodeNames(nodeList) }}
----
{{ getQuantumultXNodes(nodeList) }}
----
{{ getSurgeNodes(nodeList, customFilters.globalFilter) }}
2 changes: 2 additions & 0 deletions test/snapshots/cli.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ Generated by [AVA](https://ava.li).
shadowsocks=server:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=www.bing.com, tag=ss2␊
shadowsocks=server:443, method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=example.com, tag=ss4␊
shadowsocks=127.0.0.1:1234, method=aes-128-cfb, password=aaabbb, ssr-protocol=auth_aes128_md5, ssr-protocol-param=, obfs=tls1.2_ticket_auth, obfs-host=breakwa11.moe, udp-relay=true, fast-open=true, tag=测试中文␊
----␊
测试中文 = external, exec = "/usr/local/bin/ssr-local", args = "-s", args = "127.0.0.1", args = "-p", args = "1234", args = "-m", args = "aes-128-cfb", args = "-o", args = "tls1.2_ticket_auth", args = "-O", args = "auth_aes128_md5", args = "-k", args = "aaabbb", args = "-l", args = "61107", args = "-b", args = "127.0.0.1", args = "-g", args = "breakwa11.moe", local-port = 61107, addresses = 127.0.0.1␊
`
Binary file modified test/snapshots/cli.test.ts.snap
Binary file not shown.

0 comments on commit 1701b85

Please sign in to comment.