mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-27 23:13:43 +00:00
fix: 优化 Surge 与 SurgeMac 的不支持代理处理和降级逻辑
- 将 Surge 生成器中的不支持错误统一为 SurgeUnsupportedProxyError,便于上层识别兼容性限制 - SurgeMac 在 useMihomoExternal 场景下仅对不支持错误尝试回退到 Mihomo,否则保留原异常 - 回退失败时给出更明确的手动切换提示,降低误判与排障成本 - 调整部分告警级别为 warn,避免非法 UUID/非 IP 地址误导用户 - 新增测试,覆盖 SurgeMac 不支持节点在 external 模式下不再强制包装为 Mihomo
This commit is contained in:
4 files changed
+61
-18
No files matched your search
@@ -89,7 +89,7 @@ function parse(raw) {
|
||||
if (['vless', 'vmess'].includes(proxy.type)) {
|
||||
const isProxyUUIDValid = isValidUUID(proxy.uuid);
|
||||
if (!isProxyUUIDValid) {
|
||||
$.info(`UUID may be invalid: ${proxy.name} ${proxy.uuid}`);
|
||||
$.warn(`UUID may be invalid: ${proxy.name} ${proxy.uuid}`);
|
||||
}
|
||||
// return isProxyUUIDValid;
|
||||
} else if (['hysteria2'].includes(proxy.type)) {
|
||||
@@ -281,7 +281,7 @@ function produce(proxies, targetPlatform, type, opts = {}) {
|
||||
if (['vless', 'vmess'].includes(proxy.type)) {
|
||||
const isProxyUUIDValid = isValidUUID(proxy.uuid);
|
||||
if (!isProxyUUIDValid)
|
||||
$.info(`UUID may be invalid: ${proxy.name} ${proxy.uuid}`);
|
||||
$.warn(`UUID may be invalid: ${proxy.name} ${proxy.uuid}`);
|
||||
// return isProxyUUIDValid;
|
||||
const isVlessType = proxy.type === 'vless';
|
||||
const realityChecks = isVlessType
|
||||
|
||||
@@ -4,6 +4,17 @@ import $ from '@/core/app';
|
||||
|
||||
const targetPlatform = 'Surge';
|
||||
|
||||
export class SurgeUnsupportedProxyError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = 'SurgeUnsupportedProxyError';
|
||||
}
|
||||
}
|
||||
|
||||
function unsupported(message) {
|
||||
return new SurgeUnsupportedProxyError(message);
|
||||
}
|
||||
|
||||
const ipVersions = {
|
||||
dual: 'dual',
|
||||
ipv4: 'v4-only',
|
||||
@@ -18,7 +29,7 @@ export default function Surge_Producer() {
|
||||
['ws'].includes(proxy.network) &&
|
||||
proxy['ws-opts']?.['v2ray-http-upgrade']
|
||||
) {
|
||||
throw new Error(
|
||||
throw unsupported(
|
||||
`Platform ${targetPlatform} does not support network ${proxy.network} with http upgrade`,
|
||||
);
|
||||
}
|
||||
@@ -62,14 +73,14 @@ export default function Surge_Producer() {
|
||||
(!['tcp'].includes(proxy.network) ||
|
||||
(['tcp'].includes(proxy.network) && proxy['reality-opts']))
|
||||
) {
|
||||
throw new Error(
|
||||
throw unsupported(
|
||||
`Platform ${targetPlatform} does not support proxy type ${proxy.type} with network or reality`,
|
||||
);
|
||||
}
|
||||
|
||||
return anytls(proxy);
|
||||
}
|
||||
throw new Error(
|
||||
throw unsupported(
|
||||
`Platform ${targetPlatform} does not support proxy type: ${proxy.type}`,
|
||||
);
|
||||
};
|
||||
@@ -114,7 +125,7 @@ function shadowsocks(proxy) {
|
||||
'2022-blake3-aes-256-gcm',
|
||||
].includes(proxy.cipher)
|
||||
) {
|
||||
throw new Error(`cipher ${proxy.cipher} is not supported`);
|
||||
throw unsupported(`cipher ${proxy.cipher} is not supported`);
|
||||
}
|
||||
result.append(`,encrypt-method=${proxy.cipher}`);
|
||||
result.appendIfPresent(`,password="${proxy.password}"`, 'password');
|
||||
@@ -140,7 +151,7 @@ function shadowsocks(proxy) {
|
||||
'plugin-opts.path',
|
||||
);
|
||||
} else if (!['shadow-tls'].includes(proxy.plugin)) {
|
||||
throw new Error(`plugin ${proxy.plugin} is not supported`);
|
||||
throw unsupported(`plugin ${proxy.plugin} is not supported`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +205,7 @@ function shadowsocks(proxy) {
|
||||
}
|
||||
if (version) {
|
||||
if (version < 2) {
|
||||
throw new Error(
|
||||
throw unsupported(
|
||||
`shadow-tls version ${version} is not supported`,
|
||||
);
|
||||
}
|
||||
@@ -593,7 +604,7 @@ function ssh(proxy) {
|
||||
}
|
||||
function http(proxy) {
|
||||
if (proxy.headers && Object.keys(proxy.headers).length > 0) {
|
||||
throw new Error(`headers is unsupported`);
|
||||
throw unsupported(`headers is unsupported`);
|
||||
}
|
||||
const result = new Result(proxy);
|
||||
const type = proxy.tls ? 'https' : 'http';
|
||||
@@ -1166,7 +1177,7 @@ function wireguard_surge(proxy) {
|
||||
|
||||
function hysteria2(proxy) {
|
||||
if (proxy['obfs-password'] && proxy.obfs != 'salamander') {
|
||||
throw new Error(`only salamander obfs is supported`);
|
||||
throw unsupported(`only salamander obfs is supported`);
|
||||
}
|
||||
|
||||
const result = new Result(proxy);
|
||||
@@ -1300,9 +1311,9 @@ function handleTransport(result, proxy, includeUnsupportedProxy) {
|
||||
['tcp'].includes(proxy.network) &&
|
||||
proxy['reality-opts']
|
||||
) {
|
||||
throw new Error(`reality is unsupported`);
|
||||
throw unsupported(`reality is unsupported`);
|
||||
} else if (!['tcp'].includes(proxy.network)) {
|
||||
throw new Error(`network ${proxy.network} is unsupported`);
|
||||
throw unsupported(`network ${proxy.network} is unsupported`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Base64 } from 'js-base64';
|
||||
import { Result, isPresent } from './utils';
|
||||
import Surge_Producer from './surge';
|
||||
import Surge_Producer, { SurgeUnsupportedProxyError } from './surge';
|
||||
import ClashMeta_Producer from './clashmeta';
|
||||
import { isIPv4, isIPv6 } from '@/utils';
|
||||
import $ from '@/core/app';
|
||||
@@ -23,16 +23,27 @@ export default function SurgeMac_Producer() {
|
||||
try {
|
||||
return surge_Producer.produce(proxy, type, opts);
|
||||
} catch (e) {
|
||||
if (opts.useMihomoExternal) {
|
||||
if (
|
||||
opts.useMihomoExternal &&
|
||||
e instanceof SurgeUnsupportedProxyError
|
||||
) {
|
||||
const output = mihomo(proxy, type, opts);
|
||||
if (!output) {
|
||||
throw e;
|
||||
}
|
||||
$.log(
|
||||
`${proxy.name} is not supported on ${targetPlatform}, try to use Mihomo(SurgeMac - External Proxy Program) instead`,
|
||||
);
|
||||
return mihomo(proxy, type, opts);
|
||||
} else {
|
||||
return output;
|
||||
}
|
||||
|
||||
if (e instanceof SurgeUnsupportedProxyError) {
|
||||
throw new Error(
|
||||
`Surge for macOS 可手动指定链接参数 target=SurgeMac 或在 同步配置 中指定 SurgeMac 来启用 mihomo 支援 Surge 本身不支持的协议`,
|
||||
`${e.message}. Surge for macOS 可手动指定链接参数 target=SurgeMac 或在 同步配置 中指定 SurgeMac 来启用 mihomo 支援 Surge 本身不支持的协议`,
|
||||
);
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -187,7 +198,7 @@ function mihomo(proxy, type, opts) {
|
||||
if (isIP(proxy.server)) {
|
||||
external_proxy.addresses.push(proxy.server);
|
||||
} else {
|
||||
$.log(
|
||||
$.warn(
|
||||
`Platform ${targetPlatform}, proxy type ${proxy.type}: addresses should be an IP address, but got ${proxy.server}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -610,6 +610,27 @@ describe('Proxy text producers', function () {
|
||||
expect(output).to.include('udp-relay=true');
|
||||
});
|
||||
|
||||
it('does not wrap malformed SurgeMac nodes with Mihomo external mode', function () {
|
||||
const output = ProxyUtils.produce(
|
||||
[
|
||||
{
|
||||
type: 'ss',
|
||||
name: 'Broken Obfs',
|
||||
server: 'ss.example.com',
|
||||
port: 8388,
|
||||
cipher: 'aes-128-gcm',
|
||||
password: 'secret',
|
||||
plugin: 'obfs',
|
||||
},
|
||||
],
|
||||
'SurgeMac',
|
||||
'external',
|
||||
{ useMihomoExternal: true, localPort: 16666 },
|
||||
);
|
||||
|
||||
expect(output).to.equal('');
|
||||
});
|
||||
|
||||
it('forces SurgeMac nodes with _mihomoExternal to use Mihomo external mode', function () {
|
||||
const output = produceExternal(
|
||||
'SurgeMac',
|
||||
|
||||
Reference in new issue
Block a user