From 15aff6fa2bf27f78775677e2e5f7815a9fad415f Mon Sep 17 00:00:00 2001 From: xream Date: Fri, 19 Jul 2024 14:56:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=84=E7=90=86=E7=AB=AF=E5=8F=A3?= =?UTF-8?q?=E8=B7=B3=E8=B7=83(=E6=84=9F=E8=B0=A2=E4=BA=9A=E6=89=98?= =?UTF-8?q?=E8=8E=89=E4=BD=AC)?= 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 | 29 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/backend/package.json b/backend/package.json index f6836f533..457b4b30d 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.353", + "version": "2.14.354", "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 b8ee40a87..b12809e3c 100644 --- a/backend/src/core/proxy-utils/index.js +++ b/backend/src/core/proxy-utils/index.js @@ -20,6 +20,23 @@ import { produceArtifact } from '@/restful/sync'; import { getFlag, removeFlag, getISO, MMDB } from '@/utils/geo'; import Gist from '@/utils/gist'; +function getRandomInt(min, max) { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min + 1)) + min; +} + +function getRandomPort(portString) { + let portParts = portString.split(','); + let randomPart = portParts[Math.floor(Math.random() * portParts.length)]; + if (randomPart.includes('-')) { + let [min, max] = randomPart.split('-').map(Number); + return getRandomInt(min, max); + } else { + return Number(randomPart); + } +} + function preprocess(raw) { for (const processor of PROXY_PREPROCESSORS) { try { @@ -220,6 +237,18 @@ function produce(proxies, targetPlatform, type, opts = {}) { delete proxy['tls-fingerprint']; } } + + // 处理 端口跳跃 + if (proxy.ports) { + if (!['ClashMeta', 'JSON'].includes(targetPlatform)) { + proxy.ports = proxy.ports.replace(/\//g, ','); + } + if (!['ClashMeta', 'Stash', 'JSON'].includes(targetPlatform)) { + proxy.port = getRandomPort(proxy.ports); + delete proxy.ports; + } + } + return proxy; });