diff --git a/docs/guide/custom-provider.md b/docs/guide/custom-provider.md index dc24c8cde..3289e441c 100644 --- a/docs/guide/custom-provider.md +++ b/docs/guide/custom-provider.md @@ -264,9 +264,9 @@ module.exports = { method: 'chacha20-ietf-poly1305', password: 'password', obfs: 'tls', // tls, http, ws, wss - 'obfs-host': 'gateway-carry.icloud.com', + obfsHost: 'gateway-carry.icloud.com', 'obfs-uri': '/', // 当 obfs 为 ws 或 wss 时可配置 - 'udp-relay': true, + udpRelay: true, tfo: false, // TCP Fast Open tls13: false, // TLS 1.3,适用于 v2ray-plugin mux: false, // 目前仅 Clash + Shadowsocks + v2ray-plugin 可用 @@ -292,7 +292,7 @@ module.exports = { obfsparam: 'music.163.com', protocol: 'auth_aes128_md5', protoparam: '', - 'udp-relay': true, + udpRelay: true, tfo: false, // TCP Fast Open } ``` @@ -314,7 +314,7 @@ module.exports = { uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd', tfo: false, // TCP Fast Open tls13: false, // TLS 1.3, TLS 开启时有效 - 'udp-relay': true, // 开启 UDP 转发 + udpRelay: true, // 开启 UDP 转发 wsHeaders: { key: 'value', }, @@ -374,7 +374,7 @@ module.exports = { sni: 'example.com', // 可选 alpn: ['http/1.1'], // 可选 skipCertVerify: true, // 可选 - 'udp-relay': true, // 可选 + udpRelay: true, // 可选 tls13: false, // TLS 1.3 network: 'ws', // 可不填 wsPath: '/', // 可选 @@ -394,7 +394,7 @@ module.exports = { password: 'password', // 可选 tls: true, // 可选 skipCertVerify: true, // 可选 - 'udp-relay': false, // 可选, 仅 Clash 支持 + udpRelay: false, // 可选, 仅 Clash 支持 sni: 'example.com', // 可选, 仅 Surge 支持 tfo: true, // 可选, 仅 Surge 支持 clientCert: 'item' // 可选, 仅 Surge 支持 @@ -417,7 +417,7 @@ module.exports = { sni: 'sni.example.com', // 可选 skipCertVerify: true, // 可选 alpn: ['h3'], // 可选,Stash 不支持空值 - 'udp-relay': false, // 可选, 仅 Clash 支持更改,Surge 默认开启 + udpRelay: false, // 可选, 仅 Clash 支持更改,Surge 默认开启 } ``` diff --git a/examples/clash-remote-snippet/provider/demo.js b/examples/clash-remote-snippet/provider/demo.js index 88ad0a8d4..d8c08a3a3 100644 --- a/examples/clash-remote-snippet/provider/demo.js +++ b/examples/clash-remote-snippet/provider/demo.js @@ -11,8 +11,8 @@ module.exports = { method: 'chacha20-ietf-poly1305', password: 'surgio', obfs: 'tls', - 'obfs-host': 'world.taobao.com', - 'udp-relay': true, + obfsHost: 'world.taobao.com', + udpRelay: true, }, { nodeName: '🇭🇰HK Netflix', @@ -22,8 +22,8 @@ module.exports = { method: 'chacha20-ietf-poly1305', password: 'surgio', obfs: 'tls', - 'obfs-host': 'world.taobao.com', - 'udp-relay': true, + obfsHost: 'world.taobao.com', + udpRelay: true, }, ], }; diff --git a/examples/quantumultx/provider/demo.js b/examples/quantumultx/provider/demo.js index 88ad0a8d4..d8c08a3a3 100644 --- a/examples/quantumultx/provider/demo.js +++ b/examples/quantumultx/provider/demo.js @@ -11,8 +11,8 @@ module.exports = { method: 'chacha20-ietf-poly1305', password: 'surgio', obfs: 'tls', - 'obfs-host': 'world.taobao.com', - 'udp-relay': true, + obfsHost: 'world.taobao.com', + udpRelay: true, }, { nodeName: '🇭🇰HK Netflix', @@ -22,8 +22,8 @@ module.exports = { method: 'chacha20-ietf-poly1305', password: 'surgio', obfs: 'tls', - 'obfs-host': 'world.taobao.com', - 'udp-relay': true, + obfsHost: 'world.taobao.com', + udpRelay: true, }, ], }; diff --git a/src/generator/__tests__/__snapshots__/artifact.test.ts.md b/src/generator/__tests__/__snapshots__/artifact.test.ts.md index 424e58270..8a98a4c6e 100644 --- a/src/generator/__tests__/__snapshots__/artifact.test.ts.md +++ b/src/generator/__tests__/__snapshots__/artifact.test.ts.md @@ -1,4 +1,4 @@ -# Snapshot report for `lib/generator/__tests__/artifact.test.ts` +# Snapshot report for `src/generator/__tests__/artifact.test.ts` The actual snapshot is saved in `artifact.test.ts.snap`. diff --git a/src/generator/__tests__/__snapshots__/template.test.ts.md b/src/generator/__tests__/__snapshots__/template.test.ts.md index 10fb8d051..518596ee0 100644 --- a/src/generator/__tests__/__snapshots__/template.test.ts.md +++ b/src/generator/__tests__/__snapshots__/template.test.ts.md @@ -1,4 +1,4 @@ -# Snapshot report for `lib/generator/__tests__/template.test.ts` +# Snapshot report for `src/generator/__tests__/template.test.ts` The actual snapshot is saved in `template.test.ts.snap`. diff --git a/src/provider/ClashProvider.ts b/src/provider/ClashProvider.ts index 59dc1cec9..9a1ba2fce 100644 --- a/src/provider/ClashProvider.ts +++ b/src/provider/ClashProvider.ts @@ -192,13 +192,13 @@ export const parseClashConfig = ( port: item.port, method: item.cipher, password: item.password, - 'udp-relay': resolveUdpRelay(item.udp, udpRelay), + udpRelay: resolveUdpRelay(item.udp, udpRelay), // obfs-local 新格式 ...(item.plugin && item.plugin === 'obfs' ? { obfs: item['plugin-opts'].mode, - 'obfs-host': item['plugin-opts'].host || 'www.bing.com', + obfsHost: item['plugin-opts'].host || 'www.bing.com', } : null), @@ -206,7 +206,7 @@ export const parseClashConfig = ( ...(item.obfs ? { obfs: item.obfs, - 'obfs-host': item['obfs-host'] || 'www.bing.com', + obfsHost: item['obfs-host'] || 'www.bing.com', } : null), @@ -216,8 +216,8 @@ export const parseClashConfig = ( item['plugin-opts'].mode === 'websocket' ? { obfs: item['plugin-opts'].tls === true ? 'wss' : 'ws', - 'obfs-host': item['plugin-opts'].host || item.server, - 'obfs-uri': item['plugin-opts'].path || '/', + obfsHost: item['plugin-opts'].host || item.server, + obfsUri: item['plugin-opts'].path || '/', wsHeaders, ...(item['plugin-opts'].tls === true ? { @@ -266,7 +266,7 @@ export const parseClashConfig = ( uuid: item.uuid, alterId: item.alterId ? `${item.alterId}` : '0', method: item.cipher || 'auto', - 'udp-relay': resolveUdpRelay(item.udp, udpRelay), + udpRelay: resolveUdpRelay(item.udp, udpRelay), tls: item.tls ?? false, network: item.network || 'tcp', ...(item.network === 'ws' @@ -317,7 +317,7 @@ export const parseClashConfig = ( psk: item.psk, obfs: _.get(item, 'obfs-opts.mode', 'http'), ...(typeof item?.['obfs-opts']?.host !== 'undefined' - ? { 'obfs-host': item['obfs-opts'].host } + ? { obfsHost: item['obfs-opts'].host } : null), ...('version' in item ? { version: item.version } : null), } as SnellNodeConfig; @@ -335,7 +335,7 @@ export const parseClashConfig = ( protocol: item.protocol, protoparam: item['protocol-param'] ?? item.protocolparam, method: item.cipher, - 'udp-relay': resolveUdpRelay(item.udp, udpRelay), + udpRelay: resolveUdpRelay(item.udp, udpRelay), } as ShadowsocksrNodeConfig; case 'trojan': { @@ -354,7 +354,7 @@ export const parseClashConfig = ( : null), ...('alpn' in item ? { alpn: item.alpn } : null), ...('sni' in item ? { sni: item.sni } : null), - 'udp-relay': resolveUdpRelay(item.udp, udpRelay), + udpRelay: resolveUdpRelay(item.udp, udpRelay), tls13: tls13 ?? false, ...(network === 'ws' ? { network: 'ws', wsPath: _.get(wsOpts, 'path', '/'), wsHeaders } @@ -369,7 +369,7 @@ export const parseClashConfig = ( hostname: item.server, port: item.port, token: item.token, - 'udp-relay': resolveUdpRelay(item.udp, udpRelay), + udpRelay: resolveUdpRelay(item.udp, udpRelay), ...('skip-cert-verify' in item ? { skipCertVerify: item['skip-cert-verify'] === true } : null), diff --git a/src/provider/CustomProvider.ts b/src/provider/CustomProvider.ts index 16f2a32d5..e804907c0 100644 --- a/src/provider/CustomProvider.ts +++ b/src/provider/CustomProvider.ts @@ -1,4 +1,5 @@ import Joi from 'joi'; + import { CustomProviderConfig, NodeTypeEnum, @@ -21,6 +22,9 @@ export default class CustomProvider extends Provider { enable: Joi.boolean().strict(), tfo: Joi.boolean().strict(), mptcp: Joi.boolean().strict(), + udpRelay: Joi.boolean().strict(), + obfsHost: Joi.string(), + obfsUri: Joi.string(), shadowTls: Joi.object({ password: Joi.string().required(), sni: Joi.string(), @@ -50,24 +54,29 @@ export default class CustomProvider extends Provider { } public async getNodeList(): Promise> { - const udpRelayCheckSchema = Joi.object({ - 'udp-relay': Joi.bool().strict(), - }).unknown(); - return this.nodeList.map((item) => { - const { error: udpRelayCheckError } = udpRelayCheckSchema.validate(item); - const lowercaseKeys = ['wsHeaders']; + const propertyKeysMustBeLowercase = ['wsHeaders']; + + if (this.underlyingProxy && !item.underlyingProxy) { + item.underlyingProxy = this.underlyingProxy; + } // istanbul ignore next - if (udpRelayCheckError) { - throw udpRelayCheckError; + if (item['udp-relay']) { + throw new Error('udp-relay is abandoned, please use udpRelay instead'); } - if (this.underlyingProxy && !item.underlyingProxy) { - item.underlyingProxy = this.underlyingProxy; + // istanbul ignore next + if (item['obfs-host']) { + throw new Error('obfs-host is abandoned, please use obfsHost instead'); + } + + // istanbul ignore next + if (item['udp-relay']) { + throw new Error('obfs-uri is abandoned, please use obfsUri instead'); } - lowercaseKeys.forEach((key) => { + propertyKeysMustBeLowercase.forEach((key) => { if (item[key]) { item[key] = Object.keys(item[key]).reduce((acc, curr) => { acc[curr.toLowerCase()] = item[key][curr]; diff --git a/src/provider/ShadowsocksJsonSubscribeProvider.ts b/src/provider/ShadowsocksJsonSubscribeProvider.ts index a64d4ffab..046365a30 100644 --- a/src/provider/ShadowsocksJsonSubscribeProvider.ts +++ b/src/provider/ShadowsocksJsonSubscribeProvider.ts @@ -85,7 +85,7 @@ export const getShadowsocksJSONConfig = async ( }; if (typeof udpRelay === 'boolean') { - nodeConfig['udp-relay'] = udpRelay; + nodeConfig.udpRelay = udpRelay; } if (item.plugin === 'obfs-local') { const obfs = item.plugin_opts.match(/obfs=(\w+)/); @@ -93,7 +93,7 @@ export const getShadowsocksJSONConfig = async ( if (obfs) { nodeConfig.obfs = obfs[1]; - nodeConfig['obfs-host'] = obfsHost ? obfsHost[1] : 'www.bing.com'; + nodeConfig.obfsHost = obfsHost ? obfsHost[1] : 'www.bing.com'; } } diff --git a/src/provider/ShadowsocksSubscribeProvider.ts b/src/provider/ShadowsocksSubscribeProvider.ts index ff8a9d9a7..719aa08d8 100644 --- a/src/provider/ShadowsocksSubscribeProvider.ts +++ b/src/provider/ShadowsocksSubscribeProvider.ts @@ -104,7 +104,7 @@ export const getShadowsocksSubscription = async ( const nodeConfig = parseSSUri(item); if (udpRelay !== void 0) { - (nodeConfig['udp-relay'] as boolean) = udpRelay; + (nodeConfig.udpRelay as boolean) = udpRelay; } return nodeConfig; diff --git a/src/provider/ShadowsocksrSubscribeProvider.ts b/src/provider/ShadowsocksrSubscribeProvider.ts index 5235d9fcd..9d4100971 100644 --- a/src/provider/ShadowsocksrSubscribeProvider.ts +++ b/src/provider/ShadowsocksrSubscribeProvider.ts @@ -102,7 +102,7 @@ export const getShadowsocksrSubscription = async ( const nodeConfig = parseSSRUri(str); if (udpRelay !== void 0) { - (nodeConfig['udp-relay'] as boolean) = udpRelay; + (nodeConfig.udpRelay as boolean) = udpRelay; } return nodeConfig; diff --git a/src/provider/SsdProvider.ts b/src/provider/SsdProvider.ts index 8a5090c44..f799654f1 100644 --- a/src/provider/SsdProvider.ts +++ b/src/provider/SsdProvider.ts @@ -170,13 +170,13 @@ export const parseSsdConfig = ( port: server.port ?? port, method: server.encryption ?? encryption, password: server.password ?? password, - 'udp-relay': udpRelay === true, + udpRelay: udpRelay === true, // obfs-local ...(plugin && plugin === 'simple-obfs' ? { obfs: pluginOpts.obfs as ShadowsocksNodeConfig['obfs'], - 'obfs-host': (pluginOpts['obfs-host'] as string) || 'www.bing.com', + obfsHost: (pluginOpts['obfs-host'] as string) || 'www.bing.com', } : null), @@ -184,7 +184,7 @@ export const parseSsdConfig = ( ...(plugin && plugin === 'v2ray-plugin' ? { obfs: (pluginOpts.tls as boolean) ? 'wss' : 'ws', - 'obfs-host': pluginOpts.host as string, + obfsHost: pluginOpts.host as string, } : null), }; diff --git a/src/provider/TrojanProvider.ts b/src/provider/TrojanProvider.ts index b8cffb73f..60d122aef 100644 --- a/src/provider/TrojanProvider.ts +++ b/src/provider/TrojanProvider.ts @@ -117,7 +117,7 @@ export const getTrojanSubscription = async ({ return { ...nodeConfig, - 'udp-relay': udpRelay, + udpRelay, tls13, }; }); diff --git a/src/provider/V2rayNSubscribeProvider.ts b/src/provider/V2rayNSubscribeProvider.ts index 2a5dba2ff..7b102cbd3 100644 --- a/src/provider/V2rayNSubscribeProvider.ts +++ b/src/provider/V2rayNSubscribeProvider.ts @@ -133,7 +133,7 @@ export const getV2rayNSubscription = async ({ if (item.startsWith('ss://')) { return { ...parseSSUri(item), - 'udp-relay': udpRelay, + udpRelay: udpRelay, skipCertVerify: skipCertVerify, tls13: tls13, }; @@ -184,7 +184,7 @@ export const parseJSONConfig = ( tls: config.tls === 'tls', host: config.host, path: config.path || '/', - 'udp-relay': udpRelay === true, + udpRelay: udpRelay === true, ...(config.tls === 'tls' ? { skipCertVerify: skipCertVerify ?? false, diff --git a/src/provider/__tests__/ClashProvider.test.ts b/src/provider/__tests__/ClashProvider.test.ts index 7eeffc837..290451425 100644 --- a/src/provider/__tests__/ClashProvider.test.ts +++ b/src/provider/__tests__/ClashProvider.test.ts @@ -100,7 +100,7 @@ test('getClashSubscription', async (t) => { port: 443, method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': true, + udpRelay: true, }); t.deepEqual(config.shift(), { type: NodeTypeEnum.Shadowsocks, @@ -109,9 +109,9 @@ test('getClashSubscription', async (t) => { port: 443, method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': false, + udpRelay: false, obfs: 'tls', - 'obfs-host': 'www.bing.com', + obfsHost: 'www.bing.com', }); t.deepEqual(config.shift(), { type: NodeTypeEnum.Shadowsocks, @@ -120,10 +120,10 @@ test('getClashSubscription', async (t) => { port: 443, method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': false, + udpRelay: false, obfs: 'ws', - 'obfs-host': 'server', - 'obfs-uri': '/', + obfsHost: 'server', + obfsUri: '/', wsHeaders: {}, }); t.deepEqual(config.shift(), { @@ -136,7 +136,7 @@ test('getClashSubscription', async (t) => { method: 'auto', tls: false, network: 'tcp', - 'udp-relay': false, + udpRelay: false, }); t.deepEqual(config.shift(), { type: NodeTypeEnum.Vmess, @@ -149,7 +149,7 @@ test('getClashSubscription', async (t) => { alterId: '32', method: 'auto', network: 'ws', - 'udp-relay': true, + udpRelay: true, tls: true, tls13: false, skipCertVerify: true, @@ -168,7 +168,7 @@ test('getClashSubscription', async (t) => { alterId: '32', method: 'auto', network: 'ws', - 'udp-relay': false, + udpRelay: false, tls: true, tls13: false, skipCertVerify: false, @@ -209,9 +209,9 @@ test('getClashSubscription', async (t) => { port: 443, method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': false, + udpRelay: false, obfs: 'tls', - 'obfs-host': 'example.com', + obfsHost: 'example.com', }); t.deepEqual(config.shift(), { type: NodeTypeEnum.Shadowsocks, @@ -220,10 +220,10 @@ test('getClashSubscription', async (t) => { port: 443, method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': false, + udpRelay: false, obfs: 'wss', - 'obfs-host': 'cloudflare.com', - 'obfs-uri': '/ws', + obfsHost: 'cloudflare.com', + obfsUri: '/ws', skipCertVerify: false, tls13: false, wsHeaders: {}, @@ -243,7 +243,7 @@ test('getClashSubscription udpRelay', async (t) => { port: 443, method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': true, + udpRelay: true, }); t.deepEqual(config[1], { type: NodeTypeEnum.Shadowsocks, @@ -252,9 +252,9 @@ test('getClashSubscription udpRelay', async (t) => { port: 443, method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': true, + udpRelay: true, obfs: 'tls', - 'obfs-host': 'www.bing.com', + obfsHost: 'www.bing.com', }); t.deepEqual(config[2], { type: NodeTypeEnum.Shadowsocks, @@ -263,10 +263,10 @@ test('getClashSubscription udpRelay', async (t) => { port: 443, method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': true, + udpRelay: true, obfs: 'ws', - 'obfs-host': 'server', - 'obfs-uri': '/', + obfsHost: 'server', + obfsUri: '/', wsHeaders: {}, }); t.deepEqual(config[3], { @@ -279,7 +279,7 @@ test('getClashSubscription udpRelay', async (t) => { method: 'auto', tls: false, network: 'tcp', - 'udp-relay': true, + udpRelay: true, }); }); @@ -355,7 +355,7 @@ test('snell Configurations', (t) => { port: 44046, psk: 'yourpsk', obfs: 'tls', - 'obfs-host': 'example.com', + obfsHost: 'example.com', version: '2', }, ], @@ -381,7 +381,7 @@ test('trojan configurations', (t) => { port: 443, password: 'password1', tls13: false, - 'udp-relay': false, + udpRelay: false, }, ], ); @@ -409,7 +409,7 @@ test('trojan configurations', (t) => { skipCertVerify: true, alpn: ['http/1.1'], sni: 'sni.example.com', - 'udp-relay': true, + udpRelay: true, tls13: false, }, ], @@ -442,7 +442,7 @@ test('trojan configurations', (t) => { skipCertVerify: true, alpn: ['http/1.1'], sni: 'sni.example.com', - 'udp-relay': false, + udpRelay: false, tls13: true, }, ], @@ -478,7 +478,7 @@ test('ssr', async (t) => { protocol: 'auth_sha1_v4', protoparam: '#', type: NodeTypeEnum.Shadowsocksr, - 'udp-relay': false, + udpRelay: false, }, ], ); @@ -510,7 +510,7 @@ test('ssr', async (t) => { protocol: 'auth_sha1_v4', protoparam: '#', type: NodeTypeEnum.Shadowsocksr, - 'udp-relay': true, + udpRelay: true, }, ], ); @@ -547,10 +547,10 @@ test('shadowsocks v2ray mux', async (t) => { method: 'chacha20-ietf-poly1305', password: 'password', obfs: 'wss', - 'obfs-host': 'server', - 'obfs-uri': '/', + obfsHost: 'server', + obfsUri: '/', mux: true, - 'udp-relay': false, + udpRelay: false, skipCertVerify: true, tls13: false, wsHeaders: { diff --git a/src/provider/__tests__/CustomProvider.test.ts b/src/provider/__tests__/CustomProvider.test.ts index 577f8c30f..8909adb20 100644 --- a/src/provider/__tests__/CustomProvider.test.ts +++ b/src/provider/__tests__/CustomProvider.test.ts @@ -29,7 +29,7 @@ test('CustomProvider should throw error if udp-relay is a string', async (t) => { type: NodeTypeEnum.Shadowsocks, nodeName: 'test', - 'udp-relay': 'true', + udpRelay: 'true', }, ], }); @@ -40,7 +40,7 @@ test('CustomProvider should throw error if udp-relay is a string', async (t) => }, { instanceOf: ValidationError, - message: '"udp-relay" must be a boolean', + message: '"udpRelay" must be a boolean', }, ); }); @@ -79,7 +79,7 @@ test('CustomProvider underlying proxy', async (t) => { { type: NodeTypeEnum.Shadowsocks, nodeName: 'test', - 'udp-relay': true, + udpRelay: true, }, ], }).getNodeList(), @@ -87,7 +87,7 @@ test('CustomProvider underlying proxy', async (t) => { { nodeName: 'test', type: 'shadowsocks', - 'udp-relay': true, + udpRelay: true, underlyingProxy: 'underlying-proxy', }, ], @@ -101,7 +101,7 @@ test('CustomProvider underlying proxy', async (t) => { { type: NodeTypeEnum.Shadowsocks, nodeName: 'test', - 'udp-relay': true, + udpRelay: true, underlyingProxy: 'underlying-proxy-2', }, ], @@ -110,7 +110,7 @@ test('CustomProvider underlying proxy', async (t) => { { nodeName: 'test', type: 'shadowsocks', - 'udp-relay': true, + udpRelay: true, underlyingProxy: 'underlying-proxy-2', }, ], @@ -124,7 +124,7 @@ test('CustomProvider underlying proxy', async (t) => { { type: NodeTypeEnum.Shadowsocks, nodeName: 'test', - 'udp-relay': true, + udpRelay: true, underlyingProxy: 'underlying-proxy-2', }, ], @@ -133,7 +133,7 @@ test('CustomProvider underlying proxy', async (t) => { { nodeName: 'test', type: 'shadowsocks', - 'udp-relay': true, + udpRelay: true, underlyingProxy: 'underlying-proxy-2', }, ], diff --git a/src/provider/__tests__/ShadowsocksJsonSubscribeProvider.test.ts b/src/provider/__tests__/ShadowsocksJsonSubscribeProvider.test.ts index ebbdddadc..4eba7fb9f 100644 --- a/src/provider/__tests__/ShadowsocksJsonSubscribeProvider.test.ts +++ b/src/provider/__tests__/ShadowsocksJsonSubscribeProvider.test.ts @@ -29,9 +29,9 @@ test('getShadowsocksJSONConfig', async (t) => { port: 443, method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': true, + udpRelay: true, obfs: 'tls', - 'obfs-host': 'gateway-carry.icloud.com', + obfsHost: 'gateway-carry.icloud.com', }); t.deepEqual(config[1], { nodeName: '🇺🇸US 2', @@ -40,7 +40,7 @@ test('getShadowsocksJSONConfig', async (t) => { port: 444, method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': true, + udpRelay: true, }); t.deepEqual(config[2], { nodeName: '🇺🇸US 3', @@ -49,9 +49,9 @@ test('getShadowsocksJSONConfig', async (t) => { port: 445, method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': true, + udpRelay: true, obfs: 'tls', - 'obfs-host': 'www.bing.com', + obfsHost: 'www.bing.com', }); t.deepEqual(config[3], { nodeName: '🇺🇸US 4', @@ -60,9 +60,9 @@ test('getShadowsocksJSONConfig', async (t) => { port: 80, method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': true, + udpRelay: true, obfs: 'http', - 'obfs-host': 'www.bing.com', + obfsHost: 'www.bing.com', }); t.deepEqual(config2[0], { nodeName: '🇺🇸US 1', @@ -71,8 +71,8 @@ test('getShadowsocksJSONConfig', async (t) => { port: 443, method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': false, + udpRelay: false, obfs: 'tls', - 'obfs-host': 'gateway-carry.icloud.com', + obfsHost: 'gateway-carry.icloud.com', }); }); diff --git a/src/provider/__tests__/ShadowsocksSubscribeProvider.test.ts b/src/provider/__tests__/ShadowsocksSubscribeProvider.test.ts index 886c9efa3..cdcdf28f8 100644 --- a/src/provider/__tests__/ShadowsocksSubscribeProvider.test.ts +++ b/src/provider/__tests__/ShadowsocksSubscribeProvider.test.ts @@ -25,9 +25,9 @@ test('getShadowsocksSubscription with udp', async (t) => { port: '443', method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': true, + udpRelay: true, obfs: 'tls', - 'obfs-host': 'gateway-carry.icloud.com', + obfsHost: 'gateway-carry.icloud.com', }); t.deepEqual(nodeList[1], { nodeName: '🇺🇸US 2', @@ -36,7 +36,7 @@ test('getShadowsocksSubscription with udp', async (t) => { port: '443', method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': true, + udpRelay: true, }); t.deepEqual(nodeList[2], { nodeName: '🇺🇸US 3', @@ -45,9 +45,9 @@ test('getShadowsocksSubscription with udp', async (t) => { port: '443', method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': true, + udpRelay: true, obfs: 'wss', - 'obfs-host': 'gateway-carry.icloud.com', + obfsHost: 'gateway-carry.icloud.com', }); }); @@ -64,7 +64,7 @@ test('getShadowsocksSubscription without udp', async (t) => { method: 'chacha20-ietf-poly1305', password: 'password', obfs: 'tls', - 'obfs-host': 'gateway-carry.icloud.com', + obfsHost: 'gateway-carry.icloud.com', }); t.deepEqual(nodeList[1], { nodeName: '🇺🇸US 2', diff --git a/src/provider/__tests__/ShadowsocksrSubscribeProvider.test.ts b/src/provider/__tests__/ShadowsocksrSubscribeProvider.test.ts index b21a1c565..f9266a155 100644 --- a/src/provider/__tests__/ShadowsocksrSubscribeProvider.test.ts +++ b/src/provider/__tests__/ShadowsocksrSubscribeProvider.test.ts @@ -33,7 +33,7 @@ test('getShadowsocksrSubscription', async (t) => { obfsparam: 'breakwa11.moe', protocol: 'auth_aes128_md5', protoparam: '', - 'udp-relay': false, + udpRelay: false, }); t.deepEqual(nodeList2[0], { nodeName: '测试中文', @@ -46,6 +46,6 @@ test('getShadowsocksrSubscription', async (t) => { obfsparam: 'breakwa11.moe', protocol: 'auth_aes128_md5', protoparam: '', - 'udp-relay': true, + udpRelay: true, }); }); diff --git a/src/provider/__tests__/__snapshots__/SsdProvider.test.ts.md b/src/provider/__tests__/__snapshots__/SsdProvider.test.ts.md index ff0171baf..7d322e990 100644 --- a/src/provider/__tests__/__snapshots__/SsdProvider.test.ts.md +++ b/src/provider/__tests__/__snapshots__/SsdProvider.test.ts.md @@ -1,4 +1,4 @@ -# Snapshot report for `lib/provider/__tests__/SsdProvider.test.ts` +# Snapshot report for `src/provider/__tests__/SsdProvider.test.ts` The actual snapshot is saved in `SsdProvider.test.ts.snap`. @@ -14,22 +14,22 @@ Generated by [AVA](https://avajs.dev). method: 'aes-128-gcm', nodeName: 'US GIA', obfs: 'tls', - 'obfs-host': 'www.taobao.com', + obfsHost: 'www.taobao.com', password: 'password', port: 444, type: 'shadowsocks', - 'udp-relay': false, + udpRelay: false, }, { hostname: '55.55.55.55', method: 'aes-128-gcm', nodeName: 'HK GIA', obfs: 'http', - 'obfs-host': 'www.taobao.com', + obfsHost: 'www.taobao.com', password: 'password', port: 444, type: 'shadowsocks', - 'udp-relay': false, + udpRelay: false, }, ] @@ -43,22 +43,22 @@ Generated by [AVA](https://avajs.dev). method: 'aes-128-gcm', nodeName: 'Test Airport 45.45.45.45:555', obfs: 'tls', - 'obfs-host': 'www.taobao.com', + obfsHost: 'www.taobao.com', password: 'password', port: 555, type: 'shadowsocks', - 'udp-relay': false, + udpRelay: false, }, { hostname: '55.55.55.55', method: 'aes-128-gcm', nodeName: 'Test Airport 55.55.55.55:555', obfs: 'tls', - 'obfs-host': 'www.taobao.com', + obfsHost: 'www.taobao.com', password: 'password', port: 555, type: 'shadowsocks', - 'udp-relay': false, + udpRelay: false, }, ] @@ -72,21 +72,21 @@ Generated by [AVA](https://avajs.dev). method: 'aes-128-gcm', nodeName: 'US GIA', obfs: 'tls', - 'obfs-host': 'www.taobao.com', + obfsHost: 'www.taobao.com', password: 'password', port: 444, type: 'shadowsocks', - 'udp-relay': true, + udpRelay: true, }, { hostname: '55.55.55.55', method: 'aes-128-gcm', nodeName: 'HK GIA', obfs: 'http', - 'obfs-host': 'www.taobao.com', + obfsHost: 'www.taobao.com', password: 'password', port: 444, type: 'shadowsocks', - 'udp-relay': true, + udpRelay: true, }, ] diff --git a/src/provider/__tests__/__snapshots__/SsdProvider.test.ts.snap b/src/provider/__tests__/__snapshots__/SsdProvider.test.ts.snap index b6b05e836..542c8dba5 100644 Binary files a/src/provider/__tests__/__snapshots__/SsdProvider.test.ts.snap and b/src/provider/__tests__/__snapshots__/SsdProvider.test.ts.snap differ diff --git a/src/provider/__tests__/__snapshots__/V2rayNSubscribeProvider.test.ts.md b/src/provider/__tests__/__snapshots__/V2rayNSubscribeProvider.test.ts.md index c914c06cc..94285547f 100644 --- a/src/provider/__tests__/__snapshots__/V2rayNSubscribeProvider.test.ts.md +++ b/src/provider/__tests__/__snapshots__/V2rayNSubscribeProvider.test.ts.md @@ -1,4 +1,4 @@ -# Snapshot report for `lib/provider/__tests__/V2rayNSubscribeProvider.test.ts` +# Snapshot report for `src/provider/__tests__/V2rayNSubscribeProvider.test.ts` The actual snapshot is saved in `V2rayNSubscribeProvider.test.ts.snap`. @@ -14,13 +14,13 @@ Generated by [AVA](https://avajs.dev). method: 'chacha20-ietf-poly1305', nodeName: '🇺🇸US 1', obfs: 'tls', - 'obfs-host': 'gateway-carry.icloud.com', + obfsHost: 'gateway-carry.icloud.com', password: 'password', port: '443', skipCertVerify: undefined, tls13: undefined, type: 'shadowsocks', - 'udp-relay': undefined, + udpRelay: undefined, }, { hostname: 'us.example.com', @@ -31,7 +31,7 @@ Generated by [AVA](https://avajs.dev). skipCertVerify: undefined, tls13: undefined, type: 'shadowsocks', - 'udp-relay': undefined, + udpRelay: undefined, }, { alterId: '64', @@ -44,7 +44,7 @@ Generated by [AVA](https://avajs.dev). port: 8080, tls: false, type: 'vmess', - 'udp-relay': false, + udpRelay: false, uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd', }, { @@ -58,7 +58,7 @@ Generated by [AVA](https://avajs.dev). port: 8080, tls: false, type: 'vmess', - 'udp-relay': false, + udpRelay: false, uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd', }, { @@ -74,7 +74,7 @@ Generated by [AVA](https://avajs.dev). tls: true, tls13: false, type: 'vmess', - 'udp-relay': false, + udpRelay: false, uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd', }, ] @@ -95,7 +95,7 @@ Generated by [AVA](https://avajs.dev). port: 8080, tls: false, type: 'vmess', - 'udp-relay': false, + udpRelay: false, uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd', }, ] @@ -116,7 +116,7 @@ Generated by [AVA](https://avajs.dev). port: 8080, tls: false, type: 'vmess', - 'udp-relay': true, + udpRelay: true, uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd', }, ] diff --git a/src/provider/__tests__/__snapshots__/V2rayNSubscribeProvider.test.ts.snap b/src/provider/__tests__/__snapshots__/V2rayNSubscribeProvider.test.ts.snap index 070d55da8..f1ade4573 100644 Binary files a/src/provider/__tests__/__snapshots__/V2rayNSubscribeProvider.test.ts.snap and b/src/provider/__tests__/__snapshots__/V2rayNSubscribeProvider.test.ts.snap differ diff --git a/src/types.ts b/src/types.ts index 90f2a7444..b8ea4f90b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -197,10 +197,10 @@ export interface ShadowsocksNodeConfig extends SimpleNodeConfig { readonly port: number | string; readonly method: string; readonly password: string; - readonly 'udp-relay'?: boolean; + readonly udpRelay?: boolean; readonly obfs?: 'tls' | 'http' | 'ws' | 'wss'; - readonly 'obfs-host'?: string; - readonly 'obfs-uri'?: string; + readonly obfsHost?: string; + readonly obfsUri?: string; readonly skipCertVerify?: boolean; readonly wsHeaders?: Record; readonly tls13?: boolean; @@ -213,7 +213,7 @@ export interface SnellNodeConfig extends SimpleNodeConfig { readonly port: number | string; readonly psk: string; readonly obfs?: string; - readonly 'obfs-host'?: string; + readonly obfsHost?: string; readonly version?: string; readonly reuse?: boolean; } @@ -228,7 +228,7 @@ export interface ShadowsocksrNodeConfig extends SimpleNodeConfig { readonly password: string; readonly obfsparam: string; readonly protoparam: string; - readonly 'udp-relay'?: boolean; + readonly udpRelay?: boolean; } export interface VmessNodeConfig extends SimpleNodeConfig { @@ -242,7 +242,7 @@ export interface VmessNodeConfig extends SimpleNodeConfig { readonly tls: boolean; readonly host?: string; readonly path?: string; - readonly 'udp-relay'?: boolean; + readonly udpRelay?: boolean; readonly tls13?: boolean; readonly skipCertVerify?: boolean; readonly wsHeaders?: Record; @@ -252,7 +252,7 @@ export interface VmessNodeConfig extends SimpleNodeConfig { export interface TrojanNodeConfig extends TlsNodeConfig { readonly type: NodeTypeEnum.Trojan; readonly password: string; - readonly 'udp-relay'?: boolean; + readonly udpRelay?: boolean; readonly network?: 'tcp' | 'ws'; readonly wsPath?: string; readonly wsHeaders?: Record; @@ -261,7 +261,7 @@ export interface TrojanNodeConfig extends TlsNodeConfig { export interface TuicNodeConfig extends TlsNodeConfig { readonly type: NodeTypeEnum.Tuic; readonly token: string; - readonly 'udp-relay'?: boolean; + readonly udpRelay?: boolean; } export interface Socks5NodeConfig extends SimpleNodeConfig { diff --git a/src/utils/__tests__/__snapshots__/index.test.ts.md b/src/utils/__tests__/__snapshots__/index.test.ts.md index 3842b1830..5366fb169 100644 --- a/src/utils/__tests__/__snapshots__/index.test.ts.md +++ b/src/utils/__tests__/__snapshots__/index.test.ts.md @@ -1,4 +1,4 @@ -# Snapshot report for `lib/utils/__tests__/index.test.ts` +# Snapshot report for `src/utils/__tests__/index.test.ts` The actual snapshot is saved in `index.test.ts.snap`. diff --git a/src/utils/__tests__/__snapshots__/remote-snippet.test.ts.md b/src/utils/__tests__/__snapshots__/remote-snippet.test.ts.md index c657a0881..a95f05f6d 100644 --- a/src/utils/__tests__/__snapshots__/remote-snippet.test.ts.md +++ b/src/utils/__tests__/__snapshots__/remote-snippet.test.ts.md @@ -1,4 +1,4 @@ -# Snapshot report for `lib/utils/__tests__/remote-snippet.test.ts` +# Snapshot report for `src/utils/__tests__/remote-snippet.test.ts` The actual snapshot is saved in `remote-snippet.test.ts.snap`. diff --git a/src/utils/__tests__/__snapshots__/remote-snippet.test.ts.snap b/src/utils/__tests__/__snapshots__/remote-snippet.test.ts.snap index 47571d329..eadcce454 100644 Binary files a/src/utils/__tests__/__snapshots__/remote-snippet.test.ts.snap and b/src/utils/__tests__/__snapshots__/remote-snippet.test.ts.snap differ diff --git a/src/utils/__tests__/clash.test.ts b/src/utils/__tests__/clash.test.ts index a275a9874..6423de164 100644 --- a/src/utils/__tests__/clash.test.ts +++ b/src/utils/__tests__/clash.test.ts @@ -47,8 +47,8 @@ test('getClashNodes', async (t) => { method: 'chacha20-ietf-poly1305', password: 'password', obfs: 'tls', - 'obfs-host': 'example.com', - 'udp-relay': true, + obfsHost: 'example.com', + udpRelay: true, }, { nodeName: 'Test Node 2', @@ -230,7 +230,7 @@ test('getClashNodes', async (t) => { path: '/', port: 8080, tls: true, - 'udp-relay': true, + udpRelay: true, skipCertVerify: true, type: NodeTypeEnum.Vmess, uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd', @@ -285,7 +285,7 @@ test('getClashNodes', async (t) => { port: 443, psk: 'psk', obfs: 'tls', - 'obfs-host': 'example.com', + obfsHost: 'example.com', version: '2', }, ]), @@ -348,7 +348,7 @@ test('getClashNodes', async (t) => { hostname: '1.1.1.1', port: 443, password: 'password1', - 'udp-relay': true, + udpRelay: true, alpn: ['h2', 'http/1.1'], sni: 'example.com', skipCertVerify: true, @@ -376,7 +376,7 @@ test('getClashNodes', async (t) => { hostname: '1.1.1.1', port: 443, password: 'password1', - 'udp-relay': true, + udpRelay: true, alpn: ['h2', 'http/1.1'], sni: 'example.com', skipCertVerify: true, @@ -409,7 +409,7 @@ test('getClashNodes', async (t) => { hostname: '1.1.1.1', port: 443, password: 'password1', - 'udp-relay': true, + udpRelay: true, alpn: ['h2', 'http/1.1'], sni: 'example.com', skipCertVerify: true, @@ -550,7 +550,7 @@ test('getClashNodes', async (t) => { hostname: '1.1.1.1', port: 443, token: 'password', - 'udp-relay': false, + udpRelay: false, skipCertVerify: true, alpn: ['h3'], }, diff --git a/src/utils/__tests__/index.test.ts b/src/utils/__tests__/index.test.ts index 2245f8dc7..eb2ac3f1d 100644 --- a/src/utils/__tests__/index.test.ts +++ b/src/utils/__tests__/index.test.ts @@ -50,8 +50,8 @@ test('getShadowsocksNodes', async (t) => { method: 'chacha20-ietf-poly1305', password: 'password', obfs: 'tls', - 'obfs-host': 'gateway.icloud.com', - 'udp-relay': true, + obfsHost: 'gateway.icloud.com', + udpRelay: true, }, ]; const txt1 = utils.getShadowsocksNodes(nodeList, 'GroupName'); @@ -129,8 +129,8 @@ test('getMellowNodes', async (t) => { method: 'chacha20-ietf-poly1305', password: 'password', obfs: 'tls', - 'obfs-host': 'gateway.icloud.com', - 'udp-relay': true, + obfsHost: 'gateway.icloud.com', + udpRelay: true, }, ]; diff --git a/src/utils/__tests__/loon.test.ts b/src/utils/__tests__/loon.test.ts index 79e341ce9..2b4759396 100644 --- a/src/utils/__tests__/loon.test.ts +++ b/src/utils/__tests__/loon.test.ts @@ -17,7 +17,7 @@ test('getLoonNodes', (t) => { port: 443, tls: true, tls13: true, - 'udp-relay': true, + udpRelay: true, uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd', }, ]), @@ -74,7 +74,7 @@ test('getLoonNodes', (t) => { hostname: 'example.com', port: 443, password: 'password1', - 'udp-relay': true, + udpRelay: true, skipCertVerify: true, tfo: true, }, @@ -90,7 +90,7 @@ test('getLoonNodes', (t) => { port: 443, password: 'password1', sni: 'sni.example.com', - 'udp-relay': true, + udpRelay: true, skipCertVerify: true, tfo: true, tls13: true, @@ -107,7 +107,7 @@ test('getLoonNodes', (t) => { port: 443, password: 'password1', sni: 'sni.example.com', - 'udp-relay': true, + udpRelay: true, skipCertVerify: true, tfo: true, tls13: true, @@ -134,7 +134,7 @@ test('getLoonNodes error', (t) => { port: 443, password: 'password1', sni: 'sni.example.com', - 'udp-relay': true, + udpRelay: true, skipCertVerify: true, tfo: true, tls13: true, diff --git a/src/utils/__tests__/quantumult.test.ts b/src/utils/__tests__/quantumult.test.ts index 2243d9654..4054f6ef6 100644 --- a/src/utils/__tests__/quantumult.test.ts +++ b/src/utils/__tests__/quantumult.test.ts @@ -43,7 +43,7 @@ test('getQuantumultXNodes', (t) => { port: 8080, tls: false, host: '', - 'udp-relay': true, + udpRelay: true, uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd', }, { @@ -73,9 +73,9 @@ test('getQuantumultXNodes', (t) => { port: 443, method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': true, + udpRelay: true, obfs: 'tls', - 'obfs-host': 'gateway-carry.icloud.com', + obfsHost: 'gateway-carry.icloud.com', tfo: true, }, { @@ -133,7 +133,7 @@ test('getQuantumultXNodes', (t) => { port: 443, tls: true, tls13: true, - 'udp-relay': true, + udpRelay: true, uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd', }, ]), @@ -152,7 +152,7 @@ test('getQuantumultXNodes', (t) => { port: 443, tls: true, tls13: true, - 'udp-relay': true, + udpRelay: true, uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd', quantumultXConfig: { vmessAEAD: true, @@ -195,7 +195,7 @@ test('getQuantumultXNodes', (t) => { hostname: 'example.com', port: 443, password: 'password1', - 'udp-relay': true, + udpRelay: true, skipCertVerify: true, tfo: true, }, @@ -211,7 +211,7 @@ test('getQuantumultXNodes', (t) => { port: 443, password: 'password1', sni: 'sni.example.com', - 'udp-relay': true, + udpRelay: true, skipCertVerify: true, tfo: true, tls13: true, @@ -228,7 +228,7 @@ test('getQuantumultXNodes', (t) => { port: 443, password: 'password1', sni: 'sni.example.com', - 'udp-relay': true, + udpRelay: true, skipCertVerify: true, tfo: true, tls13: true, @@ -252,7 +252,7 @@ test('getQuantumultXNodes', (t) => { port: 443, password: 'password1', sni: 'sni.example.com', - 'udp-relay': true, + udpRelay: true, skipCertVerify: true, tfo: true, tls13: true, @@ -280,7 +280,7 @@ test('getQuantumultXNodes', (t) => { port: 443, tls: true, tls13: true, - 'udp-relay': true, + udpRelay: true, uuid: '1386f85e-657b-4d6e-9d56-78badb75e1fd', quantumultXConfig: { vmessAEAD: true, @@ -314,9 +314,9 @@ test('getQuantumultXNodes', (t) => { port: 443, method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': true, + udpRelay: true, obfs: 'tls', - 'obfs-host': 'gateway-carry.icloud.com', + obfsHost: 'gateway-carry.icloud.com', testUrl: 'http://example.com', }, ]), diff --git a/src/utils/__tests__/ss.test.ts b/src/utils/__tests__/ss.test.ts index 8a24b32a5..b71776a24 100644 --- a/src/utils/__tests__/ss.test.ts +++ b/src/utils/__tests__/ss.test.ts @@ -16,7 +16,7 @@ test('parseSSUri', (t) => { port: '12345', type: NodeTypeEnum.Shadowsocks, obfs: 'http', - 'obfs-host': 'example.com', + obfsHost: 'example.com', }, ); }); diff --git a/src/utils/__tests__/surfboard.test.ts b/src/utils/__tests__/surfboard.test.ts index fa0174205..93232e82b 100644 --- a/src/utils/__tests__/surfboard.test.ts +++ b/src/utils/__tests__/surfboard.test.ts @@ -23,8 +23,8 @@ test('getSurfboardNodes', async (t) => { method: 'chacha20-ietf-poly1305', password: 'password', obfs: 'tls', - 'obfs-host': 'example.com', - 'udp-relay': true, + obfsHost: 'example.com', + udpRelay: true, }, { nodeName: 'Test Node 2', @@ -51,8 +51,8 @@ test('getSurfboardNodes', async (t) => { method: 'chacha20-ietf-poly1305', password: 'password', obfs: 'tls', - 'obfs-host': 'example.com', - 'udp-relay': true, + obfsHost: 'example.com', + udpRelay: true, mptcp: true, }, { diff --git a/src/utils/__tests__/surge.test.ts b/src/utils/__tests__/surge.test.ts index 7931a42d4..b43917dbb 100644 --- a/src/utils/__tests__/surge.test.ts +++ b/src/utils/__tests__/surge.test.ts @@ -23,8 +23,8 @@ test('getSurgeNodes', async (t) => { method: 'chacha20-ietf-poly1305', password: 'password', obfs: 'tls', - 'obfs-host': 'example.com', - 'udp-relay': true, + obfsHost: 'example.com', + udpRelay: true, }, { nodeName: 'Test Node 2', @@ -110,8 +110,8 @@ test('getSurgeNodes', async (t) => { method: 'chacha20-ietf-poly1305', password: 'password', obfs: 'tls', - 'obfs-host': 'example.com', - 'udp-relay': true, + obfsHost: 'example.com', + udpRelay: true, mptcp: true, }, { diff --git a/src/utils/clash.ts b/src/utils/clash.ts index 897e9d73d..40f596d52 100644 --- a/src/utils/clash.ts +++ b/src/utils/clash.ts @@ -39,13 +39,13 @@ export const getClashNodes = function ( password: nodeConfig.password, port: nodeConfig.port, server: nodeConfig.hostname, - udp: nodeConfig['udp-relay'] === true, + udp: nodeConfig.udpRelay === true, ...(nodeConfig.obfs && ['tls', 'http'].includes(nodeConfig.obfs) ? { plugin: 'obfs', 'plugin-opts': { mode: nodeConfig.obfs, - host: nodeConfig['obfs-host'], + host: nodeConfig.obfsHost, }, } : null), @@ -61,8 +61,8 @@ export const getClashNodes = function ( 'skip-cert-verify': nodeConfig.skipCertVerify, } : null), - host: nodeConfig['obfs-host'], - path: nodeConfig['obfs-uri'] || '/', + host: nodeConfig.obfsHost, + path: nodeConfig.obfsUri || '/', mux: typeof nodeConfig.mux === 'boolean' ? nodeConfig.mux @@ -80,7 +80,7 @@ export const getClashNodes = function ( name: nodeConfig.nodeName, server: nodeConfig.hostname, port: nodeConfig.port, - udp: nodeConfig['udp-relay'] === true, + udp: nodeConfig.udpRelay === true, uuid: nodeConfig.uuid, alterId: nodeConfig.alterId, ...(nodeConfig.network === 'tcp' @@ -119,7 +119,7 @@ export const getClashNodes = function ( cipher: nodeConfig.method, 'obfs-param': nodeConfig.obfsparam ?? '', 'protocol-param': nodeConfig.protoparam ?? '', - udp: nodeConfig['udp-relay'] === true, + udp: nodeConfig.udpRelay === true, }; } @@ -132,9 +132,9 @@ export const getClashNodes = function ( psk: nodeConfig.psk, 'obfs-opts': { mode: nodeConfig.obfs, - ...(nodeConfig['obfs-host'] + ...(nodeConfig.obfsHost ? { - host: nodeConfig['obfs-host'], + host: nodeConfig.obfsHost, } : null), }, @@ -174,9 +174,7 @@ export const getClashNodes = function ( server: nodeConfig.hostname, port: nodeConfig.port, password: nodeConfig.password, - ...(nodeConfig['udp-relay'] - ? { udp: nodeConfig['udp-relay'] } - : null), + ...(nodeConfig.udpRelay ? { udp: nodeConfig.udpRelay } : null), ...(nodeConfig.alpn ? { alpn: nodeConfig.alpn } : null), ...(nodeConfig.sni ? { sni: nodeConfig.sni } : null), 'skip-cert-verify': nodeConfig.skipCertVerify === true, @@ -229,8 +227,8 @@ export const getClashNodes = function ( server: nodeConfig.hostname, port: nodeConfig.port, token: nodeConfig.token, - ...(typeof nodeConfig['udp-relay'] === 'boolean' - ? { udp: nodeConfig['udp-relay'] } + ...(typeof nodeConfig.udpRelay === 'boolean' + ? { udp: nodeConfig.udpRelay } : null), ...(nodeConfig.alpn ? { alpn: nodeConfig.alpn } : null), ...(nodeConfig.sni ? { sni: nodeConfig.sni } : null), diff --git a/src/utils/index.ts b/src/utils/index.ts index fab62a1b4..e8ba79b92 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,6 +1,5 @@ import { createLogger } from '@surgio/logger'; import fs from 'fs-extra'; -import _ from 'lodash'; import os from 'os'; import { join } from 'path'; import queryString from 'query-string'; @@ -157,15 +156,14 @@ export const getShadowsocksNodes = ( switch (nodeConfig.type) { case NodeTypeEnum.Shadowsocks: { - const config = _.cloneDeep(nodeConfig); const query: { readonly plugin?: string; readonly group?: string; } = { - ...(config.obfs + ...(nodeConfig.obfs ? { plugin: `${encodeURIComponent( - `obfs-local;obfs=${config.obfs};obfs-host=${config['obfs-host']}`, + `obfs-local;obfs=${nodeConfig.obfs};obfs-host=${nodeConfig.obfsHost}`, )}`, } : null), @@ -174,18 +172,18 @@ export const getShadowsocksNodes = ( return [ 'ss://', - toUrlSafeBase64(`${config.method}:${config.password}`), + toUrlSafeBase64(`${nodeConfig.method}:${nodeConfig.password}`), '@', - config.hostname, + nodeConfig.hostname, ':', - config.port, + nodeConfig.port, '/?', queryString.stringify(query, { encode: false, sort: false, }), '#', - encodeURIComponent(config.nodeName), + encodeURIComponent(nodeConfig.nodeName), ].join(''); } @@ -314,7 +312,7 @@ export const getShadowsocksNodesJSON = ( switch (nodeConfig.type) { case NodeTypeEnum.Shadowsocks: { - const useObfs = Boolean(nodeConfig.obfs && nodeConfig['obfs-host']); + const useObfs = Boolean(nodeConfig.obfs && nodeConfig.obfsHost); return { remarks: nodeConfig.nodeName, server: nodeConfig.hostname, @@ -328,7 +326,7 @@ export const getShadowsocksNodesJSON = ( ...(useObfs ? { plugin: 'obfs-local', - 'plugin-opts': `obfs=${nodeConfig.obfs};obfs-host=${nodeConfig['obfs-host']}`, + 'plugin-opts': `obfs=${nodeConfig.obfs};obfs-host=${nodeConfig.obfsHost}`, } : null), }; @@ -362,55 +360,6 @@ export const getNodeNames = function ( .join(separator || ', '); }; -export const generateClashProxyGroup = ( - ruleName: string, - ruleType: 'select' | 'url-test' | 'fallback' | 'load-balance', - nodeNameList: ReadonlyArray, - options: { - readonly filter?: NodeNameFilterType | SortedNodeNameFilterType; - readonly existingProxies?: ReadonlyArray; - readonly proxyTestUrl?: string; - readonly proxyTestInterval?: number; - }, -): { - readonly type: string; - readonly name: string; - readonly proxies: readonly string[]; - readonly url?: string; - readonly interval?: number; -} => { - let proxies; - - if (options.existingProxies) { - if (options.filter) { - const nodes = applyFilter(nodeNameList, options.filter); - proxies = ([] as string[]).concat( - options.existingProxies, - nodes.map((item) => item.nodeName), - ); - } else { - proxies = options.existingProxies; - } - } else { - const nodes = applyFilter(nodeNameList, options.filter); - proxies = nodes.map((item) => item.nodeName); - } - - return { - type: ruleType, - name: ruleName, - proxies, - ...(['url-test', 'fallback', 'load-balance'].includes(ruleType) - ? { - url: options.proxyTestUrl, - interval: options.proxyTestInterval, - } - : null), - }; -}; - -export const toYaml = (obj: JsonObject): string => YAML.stringify(obj); - // istanbul ignore next export const changeCase = ( str: string, diff --git a/src/utils/loon.ts b/src/utils/loon.ts index 2e1db62f4..af354fac2 100644 --- a/src/utils/loon.ts +++ b/src/utils/loon.ts @@ -37,7 +37,7 @@ export const getLoonNodes = function ( if (['http', 'tls'].includes(nodeConfig.obfs)) { config.push( nodeConfig.obfs, - nodeConfig['obfs-host'] || nodeConfig.hostname, + nodeConfig.obfsHost || nodeConfig.hostname, ); } else { logger.warn( @@ -51,7 +51,7 @@ export const getLoonNodes = function ( config.push('fast-open=true'); } - if (nodeConfig['udp-relay']) { + if (nodeConfig.udpRelay) { config.push('udp=true'); } @@ -75,7 +75,7 @@ export const getLoonNodes = function ( config.push('fast-open=true'); } - if (nodeConfig['udp-relay']) { + if (nodeConfig.udpRelay) { config.push('udp=true'); } diff --git a/src/utils/quantumult.ts b/src/utils/quantumult.ts index 8dc0d4d4f..e251bb1f0 100644 --- a/src/utils/quantumult.ts +++ b/src/utils/quantumult.ts @@ -36,7 +36,7 @@ export const getQuantumultXNodes = function ( ? `method=chacha20-ietf-poly1305` : `method=${nodeConfig.method}`, `password=${nodeConfig.uuid}`, - ...(nodeConfig['udp-relay'] ? ['udp-relay=true'] : []), + ...(nodeConfig.udpRelay ? ['udp-relay=true'] : []), ...(nodeConfig.tfo ? ['fast-open=true'] : []), ...(nodeConfig.quantumultXConfig?.vmessAEAD ? ['aead=true'] @@ -112,19 +112,16 @@ export const getQuantumultXNodes = function ( `${nodeConfig.hostname}:${nodeConfig.port}`, ...pickAndFormatStringList(nodeConfig, ['method', 'password']), ...(nodeConfig.obfs && ['http', 'tls'].includes(nodeConfig.obfs) - ? [ - `obfs=${nodeConfig.obfs}`, - `obfs-host=${nodeConfig['obfs-host']}`, - ] + ? [`obfs=${nodeConfig.obfs}`, `obfs-host=${nodeConfig.obfsHost}`] : []), ...(nodeConfig.obfs && ['ws', 'wss'].includes(nodeConfig.obfs) ? [ `obfs=${nodeConfig.obfs}`, - `obfs-host=${nodeConfig['obfs-host'] || nodeConfig.hostname}`, - `obfs-uri=${nodeConfig['obfs-uri'] || '/'}`, + `obfs-host=${nodeConfig.obfsHost || nodeConfig.hostname}`, + `obfs-uri=${nodeConfig.obfsUri || '/'}`, ] : []), - ...(nodeConfig['udp-relay'] ? [`udp-relay=true`] : []), + ...(nodeConfig.udpRelay ? [`udp-relay=true`] : []), ...(nodeConfig.tfo ? [`fast-open=${nodeConfig.tfo}`] : []), ]; @@ -167,7 +164,7 @@ export const getQuantumultXNodes = function ( `ssr-protocol-param=${nodeConfig.protoparam}`, `obfs=${nodeConfig.obfs}`, `obfs-host=${nodeConfig.obfsparam}`, - ...(nodeConfig['udp-relay'] ? [`udp-relay=true`] : []), + ...(nodeConfig.udpRelay ? [`udp-relay=true`] : []), ...(nodeConfig.tfo ? [`fast-open=${nodeConfig.tfo}`] : []), ...(typeof nodeConfig.testUrl === 'string' ? [`server_check_url=${nodeConfig.testUrl}`] @@ -209,7 +206,7 @@ export const getQuantumultXNodes = function ( ...pickAndFormatStringList(nodeConfig, ['password']), `tls-verification=${nodeConfig.skipCertVerify !== true}`, ...(nodeConfig.tfo ? [`fast-open=${nodeConfig.tfo}`] : []), - ...(nodeConfig['udp-relay'] ? [`udp-relay=true`] : []), + ...(nodeConfig.udpRelay ? [`udp-relay=true`] : []), ...(nodeConfig.tls13 ? [`tls13=${nodeConfig.tls13}`] : []), ]; diff --git a/src/utils/ss.ts b/src/utils/ss.ts index c44488de2..d401851ac 100644 --- a/src/utils/ss.ts +++ b/src/utils/ss.ts @@ -29,19 +29,19 @@ export const parseSSUri = (str: string): ShadowsocksNodeConfig => { ...(pluginInfo['obfs-local'] ? { obfs: pluginInfo.obfs as 'http' | 'tls', - 'obfs-host': pluginInfo['obfs-host'] + '', + obfsHost: pluginInfo['obfs-host'] + '', } : null), ...(pluginInfo['simple-obfs'] ? { obfs: pluginInfo.obfs as 'http' | 'tls', - 'obfs-host': pluginInfo['obfs-host'] + '', + obfsHost: pluginInfo['obfs-host'] + '', } : null), ...(pluginInfo['v2ray-plugin'] ? { obfs: pluginInfo.tls ? 'wss' : 'ws', - 'obfs-host': pluginInfo.host + '', + obfsHost: pluginInfo.host + '', } : null), }; diff --git a/src/utils/surfboard.ts b/src/utils/surfboard.ts index 8dd62299a..b76d8976c 100644 --- a/src/utils/surfboard.ts +++ b/src/utils/surfboard.ts @@ -58,12 +58,13 @@ export const getSurfboardNodes = function ( config.hostname, config.port, 'encrypt-method=' + config.method, - ...pickAndFormatStringList(config, [ - 'password', - 'udp-relay', - 'obfs', - 'obfs-host', - ]), + ...pickAndFormatStringList( + config, + ['password', 'udpRelay', 'obfs', 'obfsHost'], + { + keyFormat: 'kebabCase', + }, + ), ].join(', '), ].join(' = '); } diff --git a/src/utils/surge.ts b/src/utils/surge.ts index b7c88984d..b5573b126 100644 --- a/src/utils/surge.ts +++ b/src/utils/surge.ts @@ -64,9 +64,9 @@ export const getSurgeNodes = function ( config, [ 'password', - 'udp-relay', + 'udpRelay', 'obfs', - 'obfs-host', + 'obfsHost', 'tfo', 'mptcp', 'testUrl', @@ -150,7 +150,7 @@ export const getSurgeNodes = function ( [ 'psk', 'obfs', - 'obfs-host', + 'obfsHost', 'version', 'reuse', 'tfo', diff --git a/test/fixture/custom-filter/provider/custom.js b/test/fixture/custom-filter/provider/custom.js index 9dbb1b43a..6116dc816 100644 --- a/test/fixture/custom-filter/provider/custom.js +++ b/test/fixture/custom-filter/provider/custom.js @@ -11,9 +11,9 @@ module.exports = { port: '443', method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': true, + udpRelay: true, obfs: 'tls', - 'obfs-host': 'gateway-carry.icloud.com', + obfsHost: 'gateway-carry.icloud.com', tfo: true, }, { @@ -23,9 +23,9 @@ module.exports = { port: '443', method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': true, + udpRelay: true, obfs: 'tls', - 'obfs-host': 'gateway-carry.icloud.com', + obfsHost: 'gateway-carry.icloud.com', tfo: true, }, { @@ -35,9 +35,9 @@ module.exports = { port: '443', method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': true, + udpRelay: true, obfs: 'tls', - 'obfs-host': 'gateway-carry.icloud.com', + obfsHost: 'gateway-carry.icloud.com', tfo: true, }, ], diff --git a/test/fixture/plain/provider/custom.js b/test/fixture/plain/provider/custom.js index a51e2220f..a92cae229 100644 --- a/test/fixture/plain/provider/custom.js +++ b/test/fixture/plain/provider/custom.js @@ -11,9 +11,9 @@ module.exports = { port: '443', method: 'chacha20-ietf-poly1305', password: 'password', - 'udp-relay': true, + udpRelay: true, obfs: 'tls', - 'obfs-host': 'gateway-carry.icloud.com', + obfsHost: 'gateway-carry.icloud.com', tfo: true, mptcp: true, },