From 6d11ea0fcc6fa794c3ca95b6c2353440fe39da65 Mon Sep 17 00:00:00 2001 From: xream Date: Tue, 5 Dec 2023 21:51:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20`ProxyUtils.produce`=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=AC=AC=E4=BA=8C=E4=B8=AA=E5=8F=82=E6=95=B0=20`type`?= =?UTF-8?q?,=20=E6=9A=82=E6=97=B6=E4=BB=85=E6=94=AF=E6=8C=81=E7=9B=AE?= =?UTF-8?q?=E6=A0=87=E4=B8=BA=20`ClashMeta`=20=E6=97=B6=20`internal`=20?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E8=8A=82=E7=82=B9=E6=95=B0=E7=BB=84=E4=BE=9B?= =?UTF-8?q?=E5=BC=80=E5=8F=91=E8=80=85=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/core/proxy-utils/index.js | 6 +- .../core/proxy-utils/producers/clashmeta.js | 254 +++++++++--------- 3 files changed, 131 insertions(+), 131 deletions(-) diff --git a/backend/package.json b/backend/package.json index c39a4c8..f26389a 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.111", + "version": "2.14.112", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/index.js b/backend/src/core/proxy-utils/index.js index 1a2c737..af549e5 100644 --- a/backend/src/core/proxy-utils/index.js +++ b/backend/src/core/proxy-utils/index.js @@ -139,7 +139,7 @@ async function process(proxies, operators = [], targetPlatform, source) { return proxies; } -function produce(proxies, targetPlatform) { +function produce(proxies, targetPlatform, type) { const producer = PROXY_PRODUCERS[targetPlatform]; if (!producer) { throw new Error(`Target platform: ${targetPlatform} is not supported!`); @@ -157,7 +157,7 @@ function produce(proxies, targetPlatform) { return proxies .map((proxy) => { try { - let line = producer.produce(proxy); + let line = producer.produce(proxy, type); if ( line.length > 0 && line.includes('__SubStoreLocalPort__') @@ -182,7 +182,7 @@ function produce(proxies, targetPlatform) { .filter((line) => line.length > 0) .join('\n'); } else if (producer.type === 'ALL') { - return producer.produce(proxies); + return producer.produce(proxies, type); } } diff --git a/backend/src/core/proxy-utils/producers/clashmeta.js b/backend/src/core/proxy-utils/producers/clashmeta.js index 4dd43ce..fc27ae5 100644 --- a/backend/src/core/proxy-utils/producers/clashmeta.js +++ b/backend/src/core/proxy-utils/producers/clashmeta.js @@ -2,143 +2,143 @@ import { isPresent } from '@/core/proxy-utils/producers/utils'; export default function ClashMeta_Producer() { const type = 'ALL'; - const produce = (proxies) => { - return ( - 'proxies:\n' + - proxies - .filter((proxy) => { + const produce = (proxies, type) => { + const list = proxies + .filter((proxy) => { + if (proxy.type === 'snell' && String(proxy.version) === '4') { + return false; + } + return true; + }) + .map((proxy) => { + if (proxy.type === 'vmess') { + // handle vmess aead + if (isPresent(proxy, 'aead')) { + if (proxy.aead) { + proxy.alterId = 0; + } + delete proxy.aead; + } + if (isPresent(proxy, 'sni')) { + proxy.servername = proxy.sni; + delete proxy.sni; + } + // https://github.com/MetaCubeX/Clash.Meta/blob/Alpha/docs/config.yaml#L400 + // https://stash.wiki/proxy-protocols/proxy-types#vmess if ( - proxy.type === 'snell' && - String(proxy.version) === '4' + isPresent(proxy, 'cipher') && + ![ + 'auto', + 'aes-128-gcm', + 'chacha20-poly1305', + 'none', + ].includes(proxy.cipher) ) { - return false; + proxy.cipher = 'auto'; } - return true; - }) - .map((proxy) => { - if (proxy.type === 'vmess') { - // handle vmess aead - if (isPresent(proxy, 'aead')) { - if (proxy.aead) { - proxy.alterId = 0; - } - delete proxy.aead; - } - if (isPresent(proxy, 'sni')) { - proxy.servername = proxy.sni; - delete proxy.sni; - } - // https://github.com/MetaCubeX/Clash.Meta/blob/Alpha/docs/config.yaml#L400 - // https://stash.wiki/proxy-protocols/proxy-types#vmess - if ( - isPresent(proxy, 'cipher') && - ![ - 'auto', - 'aes-128-gcm', - 'chacha20-poly1305', - 'none', - ].includes(proxy.cipher) - ) { - proxy.cipher = 'auto'; - } - } else if (proxy.type === 'tuic') { - if (isPresent(proxy, 'alpn')) { - proxy.alpn = Array.isArray(proxy.alpn) - ? proxy.alpn - : [proxy.alpn]; - } else { - proxy.alpn = ['h3']; - } - if ( - isPresent(proxy, 'tfo') && - !isPresent(proxy, 'fast-open') - ) { - proxy['fast-open'] = proxy.tfo; - } - // https://github.com/MetaCubeX/Clash.Meta/blob/Alpha/adapter/outbound/tuic.go#L197 - if ( - (!proxy.token || proxy.token.length === 0) && - !isPresent(proxy, 'version') - ) { - proxy.version = 5; - } - } else if (proxy.type === 'hysteria') { - // auth_str 将会在未来某个时候删除 但是有的机场不规范 - if ( - isPresent(proxy, 'auth_str') && - !isPresent(proxy, 'auth-str') - ) { - proxy['auth-str'] = proxy['auth_str']; - } - if (isPresent(proxy, 'alpn')) { - proxy.alpn = Array.isArray(proxy.alpn) - ? proxy.alpn - : [proxy.alpn]; - } - if ( - isPresent(proxy, 'tfo') && - !isPresent(proxy, 'fast-open') - ) { - proxy['fast-open'] = proxy.tfo; - } - } else if (proxy.type === 'wireguard') { - proxy.keepalive = - proxy.keepalive ?? proxy['persistent-keepalive']; - proxy['persistent-keepalive'] = proxy.keepalive; - proxy['preshared-key'] = - proxy['preshared-key'] ?? proxy['pre-shared-key']; - proxy['pre-shared-key'] = proxy['preshared-key']; - } else if (proxy.type === 'vless') { - if (isPresent(proxy, 'sni')) { - proxy.servername = proxy.sni; - delete proxy.sni; - } + } else if (proxy.type === 'tuic') { + if (isPresent(proxy, 'alpn')) { + proxy.alpn = Array.isArray(proxy.alpn) + ? proxy.alpn + : [proxy.alpn]; + } else { + proxy.alpn = ['h3']; } + if ( + isPresent(proxy, 'tfo') && + !isPresent(proxy, 'fast-open') + ) { + proxy['fast-open'] = proxy.tfo; + } + // https://github.com/MetaCubeX/Clash.Meta/blob/Alpha/adapter/outbound/tuic.go#L197 + if ( + (!proxy.token || proxy.token.length === 0) && + !isPresent(proxy, 'version') + ) { + proxy.version = 5; + } + } else if (proxy.type === 'hysteria') { + // auth_str 将会在未来某个时候删除 但是有的机场不规范 + if ( + isPresent(proxy, 'auth_str') && + !isPresent(proxy, 'auth-str') + ) { + proxy['auth-str'] = proxy['auth_str']; + } + if (isPresent(proxy, 'alpn')) { + proxy.alpn = Array.isArray(proxy.alpn) + ? proxy.alpn + : [proxy.alpn]; + } + if ( + isPresent(proxy, 'tfo') && + !isPresent(proxy, 'fast-open') + ) { + proxy['fast-open'] = proxy.tfo; + } + } else if (proxy.type === 'wireguard') { + proxy.keepalive = + proxy.keepalive ?? proxy['persistent-keepalive']; + proxy['persistent-keepalive'] = proxy.keepalive; + proxy['preshared-key'] = + proxy['preshared-key'] ?? proxy['pre-shared-key']; + proxy['pre-shared-key'] = proxy['preshared-key']; + } else if (proxy.type === 'vless') { + if (isPresent(proxy, 'sni')) { + proxy.servername = proxy.sni; + delete proxy.sni; + } + } + if ( + ['vmess', 'vless'].includes(proxy.type) && + proxy.network === 'http' + ) { + let httpPath = proxy['http-opts']?.path; if ( - ['vmess', 'vless'].includes(proxy.type) && - proxy.network === 'http' + isPresent(proxy, 'http-opts.path') && + !Array.isArray(httpPath) ) { - let httpPath = proxy['http-opts']?.path; - if ( - isPresent(proxy, 'http-opts.path') && - !Array.isArray(httpPath) - ) { - proxy['http-opts'].path = [httpPath]; - } - let httpHost = proxy['http-opts']?.headers?.Host; - if ( - isPresent(proxy, 'http-opts.headers.Host') && - !Array.isArray(httpHost) - ) { - proxy['http-opts'].headers.Host = [httpHost]; - } + proxy['http-opts'].path = [httpPath]; } + let httpHost = proxy['http-opts']?.headers?.Host; + if ( + isPresent(proxy, 'http-opts.headers.Host') && + !Array.isArray(httpHost) + ) { + proxy['http-opts'].headers.Host = [httpHost]; + } + } - if ( - ['trojan', 'tuic', 'hysteria', 'hysteria2'].includes( - proxy.type, - ) - ) { - delete proxy.tls; - } + if ( + ['trojan', 'tuic', 'hysteria', 'hysteria2'].includes( + proxy.type, + ) + ) { + delete proxy.tls; + } - if (proxy['tls-fingerprint']) { - proxy.fingerprint = proxy['tls-fingerprint']; - } - delete proxy['tls-fingerprint']; - delete proxy.subName; - delete proxy.collectionName; - if ( - ['grpc'].includes(proxy.network) && - proxy[`${proxy.network}-opts`] - ) { - delete proxy[`${proxy.network}-opts`]['_grpc-type']; - } - return ' - ' + JSON.stringify(proxy) + '\n'; - }) - .join('') - ); + if (proxy['tls-fingerprint']) { + proxy.fingerprint = proxy['tls-fingerprint']; + } + delete proxy['tls-fingerprint']; + delete proxy.subName; + delete proxy.collectionName; + if ( + ['grpc'].includes(proxy.network) && + proxy[`${proxy.network}-opts`] + ) { + delete proxy[`${proxy.network}-opts`]['_grpc-type']; + } + return proxy; + }); + + return type === 'internal' + ? list + : 'proxies:\n' + + list + .map((proxy) => ' - ' + JSON.stringify(proxy) + '\n') + .join(''); }; return { type, produce }; }