From 5fce134a0afe4ac83754ed58ea94df72b180c42f Mon Sep 17 00:00:00 2001 From: xream Date: Sun, 29 Dec 2024 16:03:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20sing-box=20includeUnsupportedProxy=20?= =?UTF-8?q?=E5=BC=80=E5=90=AF=E6=94=AF=E6=8C=81=20Hysteria2=20=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3=E8=B7=B3=E8=B7=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- .../core/proxy-utils/producers/sing-box.js | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/backend/package.json b/backend/package.json index 03b699e49..13e85c051 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.15.3", + "version": "2.15.4", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/producers/sing-box.js b/backend/src/core/proxy-utils/producers/sing-box.js index 3b4f9a229..c9fce68a5 100644 --- a/backend/src/core/proxy-utils/producers/sing-box.js +++ b/backend/src/core/proxy-utils/producers/sing-box.js @@ -568,7 +568,7 @@ const hysteriaParser = (proxy = {}) => { smuxParser(proxy.smux, parsedProxy); return parsedProxy; }; -const hysteria2Parser = (proxy = {}) => { +const hysteria2Parser = (proxy = {}, includeUnsupportedProxy) => { const parsedProxy = { tag: proxy.name, type: 'hysteria2', @@ -580,6 +580,16 @@ const hysteria2Parser = (proxy = {}) => { }; if (parsedProxy.server_port < 0 || parsedProxy.server_port > 65535) throw 'invalid port'; + if (includeUnsupportedProxy) { + if (proxy['hop-interval']) + parsedProxy.hop_interval = /^\d+$/.test(proxy['hop-interval']) + ? `${proxy['hop-interval']}s` + : proxy['hop-interval']; + if (proxy['ports']) + parsedProxy.server_ports = proxy['ports'] + .split(/\s*,\s*/) + .map((p) => p.replace(/\s*-\s*/, ':')); + } if (proxy.up) parsedProxy.up_mbps = parseInt(`${proxy.up}`, 10); if (proxy.down) parsedProxy.down_mbps = parseInt(`${proxy.down}`, 10); if (proxy.obfs === 'salamander') parsedProxy.obfs.type = 'salamander'; @@ -790,7 +800,12 @@ export default function singbox_Producer() { list.push(hysteriaParser(proxy)); break; case 'hysteria2': - list.push(hysteria2Parser(proxy)); + list.push( + hysteria2Parser( + proxy, + opts['include-unsupported-proxy'], + ), + ); break; case 'tuic': if (!proxy.token || proxy.token.length === 0) {