From dea937df6628ce2a0e1b5b9e53d01f9e467f1f17 Mon Sep 17 00:00:00 2001 From: xream Date: Sun, 17 Nov 2024 02:10:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=BB=98=E8=AE=A4=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=B5=81=E9=87=8F=E4=BF=A1=E6=81=AF=E7=9A=84=20`User-Agent`=20?= =?UTF-8?q?=E4=BB=8E=20`Quantumult%20X/1.0.30=20(iPhone14,2;=20iOS=2015.6)?= =?UTF-8?q?`=20=E6=94=B9=E4=B8=BA=20`clash`;=20=E6=B5=81=E9=87=8F=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=BC=93=E5=AD=98=E9=80=BB=E8=BE=91=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/utils/download.js | 4 ++-- backend/src/utils/flow.js | 38 +++++++++++++++++------------------ 3 files changed, 21 insertions(+), 23 deletions(-) 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); } }