From 36db057e32a8415975838a3f3b4d55f6b87aa4ac Mon Sep 17 00:00:00 2001 From: xream Date: Sat, 23 Dec 2023 21:02:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BD=93=E8=8A=82=E7=82=B9=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3=E5=8F=B7=E4=B8=BA=E5=90=88=E6=B3=95=E7=AB=AF=E5=8F=A3?= =?UTF-8?q?=E5=8F=B7=E6=97=B6,=20=E5=B0=86=E7=B1=BB=E5=9E=8B=E8=BD=AC?= =?UTF-8?q?=E4=B8=BA=E6=95=B4=E6=95=B0(=E4=BE=BF=E4=BA=8E=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E5=88=A4=E6=96=AD)?= 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 | 5 ++++- backend/src/utils/index.js | 16 +++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/backend/package.json b/backend/package.json index 259d979..e394784 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.132", + "version": "2.14.133", "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 374a2c0..7130280 100644 --- a/backend/src/core/proxy-utils/index.js +++ b/backend/src/core/proxy-utils/index.js @@ -1,5 +1,5 @@ import download from '@/utils/download'; -import { isIPv4, isIPv6 } from '@/utils'; +import { isIPv4, isIPv6, isValidPortNumber } from '@/utils'; import PROXY_PROCESSORS, { ApplyProcessor } from './processors'; import PROXY_PREPROCESSORS from './preprocessors'; import PROXY_PRODUCERS from './producers'; @@ -214,6 +214,9 @@ function safeMatch(parser, line) { } function lastParse(proxy) { + if (isValidPortNumber(proxy.port)) { + proxy.port = parseInt(proxy.port, 10); + } if (proxy.server) { proxy.server = proxy.server .trim() diff --git a/backend/src/utils/index.js b/backend/src/utils/index.js index c897216..0502b92 100644 --- a/backend/src/utils/index.js +++ b/backend/src/utils/index.js @@ -13,6 +13,12 @@ function isIPv6(ip) { return IPV6_REGEX.test(ip); } +function isValidPortNumber(port) { + return /^((6553[0-5])|(655[0-2][0-9])|(65[0-4][0-9]{2})|(6[0-4][0-9]{3})|([1-5][0-9]{4})|([0-5]{0,5})|([0-9]{1,4}))$/.test( + port, + ); +} + function isNotBlank(str) { return typeof str === 'string' && str.trim().length > 0; } @@ -29,4 +35,12 @@ function getIfPresent(obj, defaultValue) { return isPresent(obj) ? obj : defaultValue; } -export { isIPv4, isIPv6, isNotBlank, getIfNotBlank, isPresent, getIfPresent }; +export { + isIPv4, + isIPv6, + isValidPortNumber, + isNotBlank, + getIfNotBlank, + isPresent, + getIfPresent, +};