From 2a8db4a21cd7d45ec7a3016064299544b649e44b Mon Sep 17 00:00:00 2001 From: xream Date: Sat, 12 Jul 2025 11:11:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=A2=E9=98=85=E6=B5=81=E9=87=8F?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E4=B8=AD=E7=9A=84=E6=95=B0=E5=80=BC=E5=8F=96?= =?UTF-8?q?=E6=95=B4=E4=BB=A5=E5=85=BC=E5=AE=B9=E9=83=A8=E5=88=86=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E8=A7=A3=E6=9E=90;=20=E4=B8=8D=E5=8C=85?= =?UTF-8?q?=E5=90=AB=E6=9C=89=E6=95=88=E8=8A=82=E7=82=B9=E7=9A=84=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E4=B8=8D=E5=86=99=E5=85=A5=E4=B9=90=E8=A7=82=E7=BC=93?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/utils/download.js | 34 ++++++++++++++++++++++++++++++---- backend/src/utils/flow.js | 17 ++++++++++++++++- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/backend/package.json b/backend/package.json index ca46472..04617db 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.19.74", + "version": "2.19.75", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/utils/download.js b/backend/src/utils/download.js index e36e12d..a5add40 100644 --- a/backend/src/utils/download.js +++ b/backend/src/utils/download.js @@ -14,6 +14,8 @@ import $ from '@/core/app'; import { findByName } from '@/utils/database'; import { produceArtifact } from '@/restful/sync'; import PROXY_PREPROCESSORS from '@/core/proxy-utils/preprocessors'; +import { ProxyUtils } from '@/core/proxy-utils'; + const clashPreprocessor = PROXY_PREPROCESSORS.find( (processor) => processor.name === 'Clash Pre-processor', ); @@ -261,10 +263,34 @@ export default async function download( if (shouldCache) { resourceCache.set(id, body); if (customCacheKey) { - $.info( - `URL ${url}\n写入自定义缓存 ${$arguments?.cacheKey}`, - ); - $.write(body, customCacheKey); + let shouldWriteCustomCacheKey = true; + if (preprocess) { + try { + const proxies = ProxyUtils.parse(body); + if ( + !Array.isArray(proxies) || + proxies.length === 0 + ) { + $.error( + `URL ${url} 不包含有效节点\n不写入自定义缓存 ${$arguments?.cacheKey}`, + ); + shouldWriteCustomCacheKey = false; + } + } catch (e) { + $.error( + `URL ${url} 尝试解析节点失败 ${ + e.message ?? e + }\n不写入自定义缓存 ${$arguments?.cacheKey}`, + ); + shouldWriteCustomCacheKey = false; + } + } + if (shouldWriteCustomCacheKey) { + $.info( + `URL ${url}\n写入自定义缓存 ${$arguments?.cacheKey}`, + ); + $.write(body, customCacheKey); + } } } diff --git a/backend/src/utils/flow.js b/backend/src/utils/flow.js index e97805d..04feca2 100644 --- a/backend/src/utils/flow.js +++ b/backend/src/utils/flow.js @@ -334,7 +334,22 @@ export function normalizeFlowHeader(flowHeaders) { if (!kvMap.has(key)) { try { // 解码 URI 组件并保留原始值作为 fallback - const decodedValue = decodeURIComponent(encodedValue); + let decodedValue = decodeURIComponent(encodedValue); + if ( + ['upload', 'download', 'total', 'expire'].includes( + key, + ) + ) { + try { + decodedValue = Number(decodedValue).toFixed(0); + } catch (e) { + $.error( + `Failed to convert value for key "${key}=${encodedValue}": ${ + e.message ?? e + }`, + ); + } + } kvMap.set(key, decodedValue); } catch (e) { kvMap.set(key, encodedValue);