From c904ec7380656a247954aa118d33694b1a0bf044 Mon Sep 17 00:00:00 2001 From: Roy Li Date: Sun, 26 Jul 2020 22:51:05 +0800 Subject: [PATCH] feat: change config key --- docs/guide/custom-provider.md | 2 +- lib/provider/CustomProvider.ts | 2 +- lib/types.ts | 2 +- lib/utils/index.ts | 52 ++++++++++++++++---------------- test/snapshots/cli.test.ts.md | 4 +-- test/snapshots/cli.test.ts.snap | Bin 3282 -> 3280 bytes test/utils/index.test.ts | 2 +- 7 files changed, 32 insertions(+), 32 deletions(-) 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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ziZyg;`I;)pDrQU>NR>prlR^uTf0eA|2=_kJdQc&f1G?s6(Pba>m=!br3UI9a#9i|@ zx=$6~v<>dl>!)?few}lxEIIrx{n739<__JTe`0wy`eyc)DstQ9>H0d`Q;2OB>+55R zvQ`8tb^jYb;Ikg>Fq>@;*^9qzUOI+z*hViMNW=GDmVrQRPFlV6g|WPAd`@$LsC`Rv z9`}G!w3O~0%fidHXY6u&#L^zIEX}Zn+!bfmHi+pebH3XmCNRb19J4O-+}zD>H!I!k zh8;6luN!xGj##?qo;uddtqj|UsVn`cTU5nPN1JmxLPy { }, 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');