From 7beff4013febec212f7e55466c4186e9ffa0cd2d Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 8 Mar 2024 18:40:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=A2=E9=98=85=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E6=B5=81=E9=87=8F=E4=BF=A1=E6=81=AF=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E8=BF=9C=E7=A8=8B=E5=92=8C=E6=9C=AC=E5=9C=B0=E5=90=88=E5=B9=B6?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5,=20=E6=8E=92=E9=99=A4=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=BA=86=E4=B8=8D=E6=9F=A5=E8=AF=A2=E8=AE=A2=E9=98=85?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=9A=84=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/core/proxy-utils/parsers/index.js | 1 + backend/src/restful/subscriptions.js | 42 ++++++++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/backend/package.json b/backend/package.json index 95dbc16..60c99e8 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.242", + "version": "2.14.243", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/parsers/index.js b/backend/src/core/proxy-utils/parsers/index.js index bd9cd26..ab1a768 100644 --- a/backend/src/core/proxy-utils/parsers/index.js +++ b/backend/src/core/proxy-utils/parsers/index.js @@ -722,6 +722,7 @@ function Clash_All() { 'hysteria', 'hysteria2', 'wireguard', + 'ssh', ].includes(proxy.type) ) { throw new Error( diff --git a/backend/src/restful/subscriptions.js b/backend/src/restful/subscriptions.js index 17d4f53..a798e7b 100644 --- a/backend/src/restful/subscriptions.js +++ b/backend/src/restful/subscriptions.js @@ -43,7 +43,10 @@ async function getFlowInfo(req, res) { ); return; } - if (sub.source === 'local') { + if ( + sub.source === 'local' && + !['localFirst', 'remoteFirst'].includes(sub.mergeSources) + ) { failed( res, new RequestInvalidError( @@ -55,7 +58,42 @@ async function getFlowInfo(req, res) { return; } try { - const flowHeaders = await getFlowHeaders(sub.url); + let url = `${sub.url}` + .split(/[\r\n]+/) + .map((i) => i.trim()) + .filter((i) => i.length)?.[0]; + + let $arguments = {}; + const rawArgs = url.split('#'); + url = url.split('#')[0]; + if (rawArgs.length > 1) { + try { + // 支持 `#${encodeURIComponent(JSON.stringify({arg1: "1"}))}` + $arguments = JSON.parse(decodeURIComponent(rawArgs[1])); + } catch (e) { + for (const pair of rawArgs[1].split('&')) { + const key = pair.split('=')[0]; + const value = pair.split('=')[1]; + // 部分兼容之前的逻辑 const value = pair.split('=')[1] || true; + $arguments[key] = + value == null || value === '' + ? true + : decodeURIComponent(value); + } + } + } + if ($arguments.noFlow) { + failed( + res, + new RequestInvalidError( + 'NO_FLOW_INFO', + 'N/A', + `Subscription ${name}: noFlow`, + ), + ); + return; + } + const flowHeaders = await getFlowHeaders(url); if (!flowHeaders) { failed( res,