diff --git a/backend/package.json b/backend/package.json index c2a2d18..abaec5d 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.419", + "version": "2.14.420", "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 c0c8d1e..bca2068 100644 --- a/backend/src/utils/download.js +++ b/backend/src/utils/download.js @@ -151,7 +151,7 @@ export default async function download( // try to find in app cache const cached = resourceCache.get(id); if (!noCache && !$arguments?.noCache && cached) { - $.info(`使用缓存: ${url}`); + $.info(`使用缓存: ${url}, ${userAgent}`); result = cached; if (customCacheKey) { $.info(`URL ${url}\n写入自定义缓存 ${$arguments?.cacheKey}`); @@ -179,7 +179,7 @@ export default async function download( if (headers) { const flowInfo = getFlowField(headers); if (flowInfo) { - headersResourceCache.set(url, flowInfo); + headersResourceCache.set(id, flowInfo); } } if (body.replace(/\s/g, '').length === 0) diff --git a/backend/src/utils/flow.js b/backend/src/utils/flow.js index 4cff050..fa45b92 100644 --- a/backend/src/utils/flow.js +++ b/backend/src/utils/flow.js @@ -1,5 +1,6 @@ import { SETTINGS_KEY } from '@/constants'; import { HTTP, ENV } from '@/vendor/open-api'; +import { hex_md5 } from '@/vendor/md5'; import { getPolicyDescriptor } from '@/utils'; import $ from '@/core/app'; import headersResourceCache from '@/utils/headers-resource-cache'; @@ -52,29 +53,26 @@ export async function getFlowHeaders( return; } const { isStash, isLoon, isShadowRocket, isQX } = ENV(); - const cached = headersResourceCache.get(url); + const insecure = $arguments?.insecure + ? $.env.isNode + ? { strictSSL: false } + : { insecure: true } + : undefined; + const { defaultProxy, defaultFlowUserAgent, defaultTimeout } = + $.read(SETTINGS_KEY); + let proxy = customProxy || defaultProxy; + if ($.env.isNode) { + proxy = proxy || eval('process.env.SUB_STORE_BACKEND_DEFAULT_PROXY'); + } + const userAgent = ua || defaultFlowUserAgent || 'clash'; + const requestTimeout = timeout || defaultTimeout; + const id = hex_md5(userAgent + url); + const cached = headersResourceCache.get(id); let flowInfo; if (!$arguments?.noCache && cached) { - // $.info(`使用缓存的流量信息: ${url}`); + $.info(`使用缓存的流量信息: ${url}, ${userAgent}`); flowInfo = cached; } else { - const insecure = $arguments?.insecure - ? $.env.isNode - ? { strictSSL: false } - : { insecure: true } - : undefined; - const { defaultProxy, defaultFlowUserAgent, defaultTimeout } = - $.read(SETTINGS_KEY); - let proxy = customProxy || defaultProxy; - if ($.env.isNode) { - proxy = - proxy || eval('process.env.SUB_STORE_BACKEND_DEFAULT_PROXY'); - } - const userAgent = - ua || - defaultFlowUserAgent || - 'Quantumult%20X/1.0.30 (iPhone14,2; iOS 15.6)'; - const requestTimeout = timeout || defaultTimeout; const http = HTTP(); if (flowUrl) { $.info( @@ -170,7 +168,7 @@ export async function getFlowHeaders( } } if (flowInfo) { - headersResourceCache.set(url, flowInfo); + headersResourceCache.set(id, flowInfo); } }