From 1281df59f3fcb3d41e260ab2bc3cbd779c35a129 Mon Sep 17 00:00:00 2001 From: xream Date: Thu, 13 Mar 2025 20:19:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=BC=BA=20VMess=20URI=20?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=85=BC=E5=AE=B9=E6=80=A7;=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=AF=BC=E5=87=BA=E6=96=87=E4=BB=B6=E5=90=8D=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= 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 | 2 +- backend/src/restful/collections.js | 18 +++---------- backend/src/restful/file.js | 18 +++---------- backend/src/restful/miscs.js | 16 ++---------- backend/src/restful/subscriptions.js | 18 +++---------- backend/src/utils/index.js | 25 +++++++++++++++++++ 7 files changed, 41 insertions(+), 58 deletions(-) diff --git a/backend/package.json b/backend/package.json index cc57e69..32340dd 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.18.2", + "version": "2.18.3", "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 9bd2870..436eb4d 100644 --- a/backend/src/core/proxy-utils/parsers/index.js +++ b/backend/src/core/proxy-utils/parsers/index.js @@ -342,7 +342,7 @@ function URI_VMess() { }; const parse = (line) => { line = line.split('vmess://')[1]; - let content = Base64.decode(line); + let content = Base64.decode(line.replace(/\?.*?$/, '')); if (/=\s*vmess/.test(content)) { // Quantumult VMess URI format const partitions = content.split(',').map((p) => p.trim()); diff --git a/backend/src/restful/collections.js b/backend/src/restful/collections.js index d4482ce..edffbd4 100644 --- a/backend/src/restful/collections.js +++ b/backend/src/restful/collections.js @@ -3,6 +3,7 @@ import { COLLECTIONS_KEY, ARTIFACTS_KEY } from '@/constants'; import { failed, success } from '@/restful/response'; import $ from '@/core/app'; import { RequestInvalidError, ResourceNotFoundError } from '@/restful/errors'; +import { formatDateTime } from '@/utils'; export default function register($app) { if (!$.read(COLLECTIONS_KEY)) $.write({}, COLLECTIONS_KEY); @@ -60,20 +61,9 @@ function getCollection(req, res) { .set( 'content-disposition', `attachment; filename="${encodeURIComponent( - `sub-store_collection_${name}_${new Date() - .toLocaleString('zh-CN', { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false, - }) - .replace( - /^(\d+?)\/(\d+?)\/(\d+?)\s*?(\d+?):(\d+?):(\d+?)$/, - '$1-$2-$3_$4-$5-$6', - )}.json`, + `sub-store_collection_${name}_${formatDateTime( + new Date(), + )}.json`, )}"`, ) .send(JSON.stringify(collection)); diff --git a/backend/src/restful/file.js b/backend/src/restful/file.js index 467c986..9d0f2b2 100644 --- a/backend/src/restful/file.js +++ b/backend/src/restful/file.js @@ -9,6 +9,7 @@ import { InternalServerError, } from '@/restful/errors'; import { produceArtifact } from '@/restful/sync'; +import { formatDateTime } from '@/utils'; export default function register($app) { if (!$.read(FILES_KEY)) $.write([], FILES_KEY); @@ -210,20 +211,9 @@ function getWholeFile(req, res) { .set( 'content-disposition', `attachment; filename="${encodeURIComponent( - `sub-store_file_${name}_${new Date() - .toLocaleString('zh-CN', { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false, - }) - .replace( - /^(\d+?)\/(\d+?)\/(\d+?)\s*?(\d+?):(\d+?):(\d+?)$/, - '$1-$2-$3_$4-$5-$6', - )}.json`, + `sub-store_file_${name}_${formatDateTime( + new Date(), + )}.json`, )}"`, ) .send(JSON.stringify(file)); diff --git a/backend/src/restful/miscs.js b/backend/src/restful/miscs.js index 028e07d..9a84239 100644 --- a/backend/src/restful/miscs.js +++ b/backend/src/restful/miscs.js @@ -14,6 +14,7 @@ import { InternalServerError, RequestInvalidError } from '@/restful/errors'; import Gist from '@/utils/gist'; import migrate from '@/utils/migration'; import env from '@/utils/env'; +import { formatDateTime } from '@/utils'; export default function register($app) { // utils @@ -28,20 +29,7 @@ export default function register($app) { .set( 'content-disposition', `attachment; filename="${encodeURIComponent( - `sub-store_data_${new Date() - .toLocaleString('zh-CN', { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false, - }) - .replace( - /^(\d+?)\/(\d+?)\/(\d+?)\s*?(\d+?):(\d+?):(\d+?)$/, - '$1-$2-$3_$4-$5-$6', - )}.json`, + `sub-store_data_${formatDateTime(new Date())}.json`, )}"`, ) .send( diff --git a/backend/src/restful/subscriptions.js b/backend/src/restful/subscriptions.js index 1b0e162..9eb733f 100644 --- a/backend/src/restful/subscriptions.js +++ b/backend/src/restful/subscriptions.js @@ -13,6 +13,7 @@ import { } from '@/utils/flow'; import { success, failed } from './response'; import $ from '@/core/app'; +import { formatDateTime } from '@/utils'; if (!$.read(SUBS_KEY)) $.write({}, SUBS_KEY); @@ -265,20 +266,9 @@ function getSubscription(req, res) { .set( 'content-disposition', `attachment; filename="${encodeURIComponent( - `sub-store_subscription_${name}_${new Date() - .toLocaleString('zh-CN', { - year: 'numeric', - month: '2-digit', - day: '2-digit', - hour: '2-digit', - minute: '2-digit', - second: '2-digit', - hour12: false, - }) - .replace( - /^(\d+?)\/(\d+?)\/(\d+?)\s*?(\d+?):(\d+?):(\d+?)$/, - '$1-$2-$3_$4-$5-$6', - )}.json`, + `sub-store_subscription_${name}_${formatDateTime( + new Date(), + )}.json`, )}"`, ) .send(JSON.stringify(sub)); diff --git a/backend/src/utils/index.js b/backend/src/utils/index.js index daf6e76..f771d2c 100644 --- a/backend/src/utils/index.js +++ b/backend/src/utils/index.js @@ -126,7 +126,32 @@ function isValidUUID(uuid) { ); } +function formatDateTime(date, format = 'YYYY-MM-DD_HH-mm-ss') { + const d = date instanceof Date ? date : new Date(date); + + if (isNaN(d.getTime())) { + return ''; + } + + const pad = (num) => String(num).padStart(2, '0'); + + const replacements = { + YYYY: d.getFullYear(), + MM: pad(d.getMonth() + 1), + DD: pad(d.getDate()), + HH: pad(d.getHours()), + mm: pad(d.getMinutes()), + ss: pad(d.getSeconds()), + }; + + return format.replace( + /YYYY|MM|DD|HH|mm|ss/g, + (match) => replacements[match], + ); +} + export { + formatDateTime, isValidUUID, ipAddress, isIPv4,