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);