feat: ProxyUtils.produce 增加第二个参数 type, 暂时仅支持目标为 ClashMetainternal 输出节点数组供开发者使用

This commit is contained in:
xream 2023-12-05 21:51:43 +08:00
parent 75f802f607
commit 6d11ea0fcc
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
3 changed files with 131 additions and 131 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "sub-store", "name": "sub-store",
"version": "2.14.111", "version": "2.14.112",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js", "main": "src/main.js",
"scripts": { "scripts": {

View File

@ -139,7 +139,7 @@ async function process(proxies, operators = [], targetPlatform, source) {
return proxies; return proxies;
} }
function produce(proxies, targetPlatform) { function produce(proxies, targetPlatform, type) {
const producer = PROXY_PRODUCERS[targetPlatform]; const producer = PROXY_PRODUCERS[targetPlatform];
if (!producer) { if (!producer) {
throw new Error(`Target platform: ${targetPlatform} is not supported!`); throw new Error(`Target platform: ${targetPlatform} is not supported!`);
@ -157,7 +157,7 @@ function produce(proxies, targetPlatform) {
return proxies return proxies
.map((proxy) => { .map((proxy) => {
try { try {
let line = producer.produce(proxy); let line = producer.produce(proxy, type);
if ( if (
line.length > 0 && line.length > 0 &&
line.includes('__SubStoreLocalPort__') line.includes('__SubStoreLocalPort__')
@ -182,7 +182,7 @@ function produce(proxies, targetPlatform) {
.filter((line) => line.length > 0) .filter((line) => line.length > 0)
.join('\n'); .join('\n');
} else if (producer.type === 'ALL') { } else if (producer.type === 'ALL') {
return producer.produce(proxies); return producer.produce(proxies, type);
} }
} }

View File

@ -2,143 +2,143 @@ import { isPresent } from '@/core/proxy-utils/producers/utils';
export default function ClashMeta_Producer() { export default function ClashMeta_Producer() {
const type = 'ALL'; const type = 'ALL';
const produce = (proxies) => { const produce = (proxies, type) => {
return ( const list = proxies
'proxies:\n' + .filter((proxy) => {
proxies if (proxy.type === 'snell' && String(proxy.version) === '4') {
.filter((proxy) => { 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 ( if (
proxy.type === 'snell' && isPresent(proxy, 'cipher') &&
String(proxy.version) === '4' ![
'auto',
'aes-128-gcm',
'chacha20-poly1305',
'none',
].includes(proxy.cipher)
) { ) {
return false; proxy.cipher = 'auto';
} }
return true; } else if (proxy.type === 'tuic') {
}) if (isPresent(proxy, 'alpn')) {
.map((proxy) => { proxy.alpn = Array.isArray(proxy.alpn)
if (proxy.type === 'vmess') { ? proxy.alpn
// handle vmess aead : [proxy.alpn];
if (isPresent(proxy, 'aead')) { } else {
if (proxy.aead) { proxy.alpn = ['h3'];
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;
}
} }
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 ( if (
['vmess', 'vless'].includes(proxy.type) && isPresent(proxy, 'http-opts.path') &&
proxy.network === 'http' !Array.isArray(httpPath)
) { ) {
let httpPath = proxy['http-opts']?.path; proxy['http-opts'].path = [httpPath];
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];
}
} }
let httpHost = proxy['http-opts']?.headers?.Host;
if (
isPresent(proxy, 'http-opts.headers.Host') &&
!Array.isArray(httpHost)
) {
proxy['http-opts'].headers.Host = [httpHost];
}
}
if ( if (
['trojan', 'tuic', 'hysteria', 'hysteria2'].includes( ['trojan', 'tuic', 'hysteria', 'hysteria2'].includes(
proxy.type, proxy.type,
) )
) { ) {
delete proxy.tls; delete proxy.tls;
} }
if (proxy['tls-fingerprint']) { if (proxy['tls-fingerprint']) {
proxy.fingerprint = proxy['tls-fingerprint']; proxy.fingerprint = proxy['tls-fingerprint'];
} }
delete proxy['tls-fingerprint']; delete proxy['tls-fingerprint'];
delete proxy.subName; delete proxy.subName;
delete proxy.collectionName; delete proxy.collectionName;
if ( if (
['grpc'].includes(proxy.network) && ['grpc'].includes(proxy.network) &&
proxy[`${proxy.network}-opts`] proxy[`${proxy.network}-opts`]
) { ) {
delete proxy[`${proxy.network}-opts`]['_grpc-type']; delete proxy[`${proxy.network}-opts`]['_grpc-type'];
} }
return ' - ' + JSON.stringify(proxy) + '\n'; return proxy;
}) });
.join('')
); return type === 'internal'
? list
: 'proxies:\n' +
list
.map((proxy) => ' - ' + JSON.stringify(proxy) + '\n')
.join('');
}; };
return { type, produce }; return { type, produce };
} }