diff --git a/docs/guide/custom-provider.md b/docs/guide/custom-provider.md index 357ed0488..169d9f178 100644 --- a/docs/guide/custom-provider.md +++ b/docs/guide/custom-provider.md @@ -419,7 +419,7 @@ module.exports = { 2. 请不要随意将证书检查关闭; ::: -### nodeConfig['underlying-proxy'] +### nodeConfig.underlyingProxy - 类型: `String` - 默认值: `undefined` diff --git a/lib/provider/CustomProvider.ts b/lib/provider/CustomProvider.ts index 496ae1453..359c751d2 100644 --- a/lib/provider/CustomProvider.ts +++ b/lib/provider/CustomProvider.ts @@ -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({ diff --git a/lib/types.ts b/lib/types.ts index b7f833ef7..12aba4f3f 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -264,7 +264,7 @@ export interface SimpleNodeConfig { clashConfig?: CommandConfig['clashConfig']; hostnameIp?: ReadonlyArray; provider?: Provider; - 'underlying-proxy'?: string; + underlyingProxy?: string; } export interface PlainObject { readonly [name: string]: any } diff --git a/lib/utils/index.ts b/lib/utils/index.ts index 370782f29..82ffd52f8 100644 --- a/lib/utils/index.ts +++ b/lib/utils/index.ts @@ -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(' = ')); @@ -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(' = ')); @@ -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(' = ')); } @@ -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(' = ')); } @@ -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(' = ')); } @@ -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 ([ @@ -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}`, ] : []), @@ -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) { diff --git a/test/snapshots/cli.test.ts.md b/test/snapshots/cli.test.ts.md index 6952abb95..9453562fe 100644 --- a/test/snapshots/cli.test.ts.md +++ b/test/snapshots/cli.test.ts.md @@ -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␊ @@ -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␊ diff --git a/test/snapshots/cli.test.ts.snap b/test/snapshots/cli.test.ts.snap index 0072fce7f..8ba62311f 100644 Binary files a/test/snapshots/cli.test.ts.snap and b/test/snapshots/cli.test.ts.snap differ diff --git a/test/utils/index.test.ts b/test/utils/index.test.ts index 2f9fed8a6..d9d802c9d 100644 --- a/test/utils/index.test.ts +++ b/test/utils/index.test.ts @@ -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');