Skip to content

Commit

Permalink
feat: change config key
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Jul 26, 2020
1 parent 74d212c commit c904ec7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion docs/guide/custom-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ module.exports = {
2. 请不要随意将证书检查关闭;
:::

### nodeConfig['underlying-proxy'] <Badge text="v2.2.0" vertical="middle" />
### nodeConfig.underlyingProxy <Badge text="v2.2.0" vertical="middle" />

- 类型: `String`
- 默认值: `undefined`
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/CustomProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class CustomProvider extends Provider {
mptcp: Joi.boolean().strict(),
binPath: Joi.string(),
localPort: Joi.number(),
'underlying-proxy': Joi.string(),
underlyingProxy: Joi.string(),
})
.unknown();
const schema = Joi.object({
Expand Down
2 changes: 1 addition & 1 deletion lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export interface SimpleNodeConfig {
clashConfig?: CommandConfig['clashConfig'];
hostnameIp?: ReadonlyArray<string>;
provider?: Provider;
'underlying-proxy'?: string;
underlyingProxy?: string;
}

export interface PlainObject { readonly [name: string]: any }
Expand Down
52 changes: 26 additions & 26 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ export const getSurgeNodes = function(
config.hostname,
config.port,
'encrypt-method=' + config.method,
...pickAndFormatStringList(config, ['password', 'udp-relay', 'obfs', 'obfs-host', 'tfo', 'underlying-proxy']),
...(typeof config.mptcp === 'boolean' ? [
`mptcp=${config.mptcp}`,
...pickAndFormatStringList(config, ['password', 'udp-relay', 'obfs', 'obfs-host', 'tfo', 'mptcp']),
...(typeof config.underlyingProxy === 'string' ? [
`underlying-proxy=${config.underlyingProxy}`,
] : []),
].join(', ')
].join(' = '));
Expand All @@ -203,9 +203,9 @@ export const getSurgeNodes = function(
config.method,
config.password,
'https://raw.githubusercontent.com/ConnersHua/SSEncrypt/master/SSEncrypt.module',
...pickAndFormatStringList(config, ['udp-relay', 'obfs', 'obfs-host', 'tfo', 'underlying-proxy']),
...(typeof config.mptcp === 'boolean' ? [
`mptcp=${config.mptcp}`,
...pickAndFormatStringList(config, ['udp-relay', 'obfs', 'obfs-host', 'tfo', 'mptcp']),
...(typeof config.underlyingProxy === 'string' ? [
`underlying-proxy=${config.underlyingProxy}`,
] : []),
].join(', ')
].join(' = '));
Expand All @@ -222,19 +222,13 @@ export const getSurgeNodes = function(
config.port,
config.username,
config.password,
...(typeof config.tls13 === 'boolean' ? [
`tls13=${config.tls13}`,
] : []),
...(typeof config.skipCertVerify === 'boolean' ? [
`skip-cert-verify=${config.skipCertVerify}`,
] : []),
...(typeof config.tfo === 'boolean' ? [
`tfo=${config.tfo}`,
] : []),
...(typeof config.mptcp === 'boolean' ? [
`mptcp=${config.mptcp}`,
...(typeof config.underlyingProxy === 'string' ? [
`underlying-proxy=${config.underlyingProxy}`,
] : []),
...pickAndFormatStringList(config, ['sni', 'underlying-proxy']),
...pickAndFormatStringList(config, ['sni', 'tfo', 'mptcp', 'tls13']),
].join(', ')
].join(' = '));
}
Expand All @@ -250,7 +244,10 @@ export const getSurgeNodes = function(
config.port,
config.username,
config.password,
...pickAndFormatStringList(config, ['underlying-proxy']),
...(typeof config.underlyingProxy === 'string' ? [
`underlying-proxy=${config.underlyingProxy}`,
] : []),
...pickAndFormatStringList(config, ['tfo', 'mptcp']),
].join(', ')
].join(' = '));
}
Expand All @@ -264,13 +261,10 @@ export const getSurgeNodes = function(
'snell',
config.hostname,
config.port,
...pickAndFormatStringList(config, ['psk', 'obfs', 'obfs-host', 'version', 'underlying-proxy']),
...(typeof config.tfo === 'boolean' ? [
`tfo=${config.tfo}`,
] : []),
...(typeof config.mptcp === 'boolean' ? [
`mptcp=${config.mptcp}`,
...(typeof config.underlyingProxy === 'string' ? [
`underlying-proxy=${config.underlyingProxy}`,
] : []),
...pickAndFormatStringList(config, ['psk', 'obfs', 'obfs-host', 'version', 'tfo', 'mptcp']),
].join(', '),
].join(' = '));
}
Expand Down Expand Up @@ -380,8 +374,8 @@ export const getSurgeNodes = function(
configList.push(`mptcp=${config.mptcp}`);
}

if (config['underlying-proxy']) {
configList.push(`underlying-proxy=${config['underlying-proxy']}`);
if (config['underlyingProxy']) {
configList.push(`underlying-proxy=${config['underlyingProxy']}`);
}

return ([
Expand Down Expand Up @@ -435,7 +429,10 @@ export const getSurgeNodes = function(
nodeConfig.hostname,
`${nodeConfig.port}`,
`password=${nodeConfig.password}`,
...pickAndFormatStringList(nodeConfig, ['tfo', 'mptcp', 'sni', 'underlying-proxy']),
...pickAndFormatStringList(nodeConfig, ['tfo', 'mptcp', 'sni', 'tls13']),
...(typeof nodeConfig.underlyingProxy === 'string' ? [
`underlying-proxy=${nodeConfig.underlyingProxy}`,
] : []),
...(typeof nodeConfig.skipCertVerify === 'boolean' ? [
`skip-cert-verify=${nodeConfig.skipCertVerify}`,
] : []),
Expand All @@ -454,7 +451,10 @@ export const getSurgeNodes = function(
nodeConfig.tls === true ? "socks5-tls": "socks5",
nodeConfig.hostname,
nodeConfig.port,
...pickAndFormatStringList(nodeConfig, ['username', 'password', 'sni', 'tfo', 'underlying-proxy']),
...(typeof nodeConfig.underlyingProxy === 'string' ? [
`underlying-proxy=${nodeConfig.underlyingProxy}`,
] : []),
...pickAndFormatStringList(nodeConfig, ['username', 'password', 'sni', 'tfo', 'mptcp', 'tls13']),
]

if (nodeConfig.tls === true) {
Expand Down
4 changes: 2 additions & 2 deletions test/snapshots/cli.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Generated by [AVA](https://avajs.dev).
🇺🇸US 2 = ss, us.example.com, 443, encrypt-method=chacha20-ietf-poly1305, password=password, tfo=true, mptcp=true␊
🇺🇲 US = ss, us.example.com, 443, encrypt-method=chacha20-ietf-poly1305, password=password, udp-relay=true, obfs=tls, obfs-host=gateway-carry.icloud.com, tfo=true, mptcp=true␊
Snell = snell, us.example.com, 443, psk=password, obfs=tls␊
HTTPS = https, us.example.com, 443, username, password, tls13=true, tfo=true␊
HTTPS = https, us.example.com, 443, username, password, tfo=true, tls13=true␊
trojan node = trojan, trojan.example.com, 443, password=password␊
🇺🇸US 1 = ss, us.example.com, 443, encrypt-method=chacha20-ietf-poly1305, password=password, obfs=tls, obfs-host=gateway-carry.icloud.com␊
🇺🇸US 2 = ss, us.example.com, 444, encrypt-method=chacha20-ietf-poly1305, password=password␊
Expand Down Expand Up @@ -649,7 +649,7 @@ Generated by [AVA](https://avajs.dev).
ss2 = ss, server, 443, encrypt-method=chacha20-ietf-poly1305, password=password, udp-relay=true, obfs=tls, obfs-host=www.bing.com␊
vmess = vmess, server, 443, username=uuid␊
vmess custom header = vmess, server, 443, username=uuid, ws=true, ws-path=/path, ws-headers="host:server|user-agent:Mozilla/5.0 (iPhone; CPU iPhone OS 13_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Mobile/15E148 Safari/604.1|edge:www.baidu.com", tls=true, tls13=true, skip-cert-verify=false, sni=server␊
http 1 = https, server, 443, username, password, tls13=true, skip-cert-verify=false␊
http 1 = https, server, 443, username, password, skip-cert-verify=false, tls13=true
http 2 = http, server, 443, username, password␊
snell = snell, server, 44046, psk=yourpsk, obfs=http␊
ss4 = ss, server, 443, encrypt-method=chacha20-ietf-poly1305, password=password, udp-relay=true, obfs=tls, obfs-host=example.com␊
Expand Down
Binary file modified test/snapshots/cli.test.ts.snap
Binary file not shown.
2 changes: 1 addition & 1 deletion test/utils/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ test('getSurgeNodes', async t => {
},
tfo: true,
mptcp: true,
'underlying-proxy': 'another-proxy',
underlyingProxy: 'another-proxy',
}];
const txt1 = utils.getSurgeNodes(nodeList).split('\n');
const txt2 = utils.getSurgeNodes(nodeList, nodeConfig => nodeConfig.nodeName === 'Test Node 1');
Expand Down

0 comments on commit c904ec7

Please sign in to comment.