From f4cdc953e636d5c811bfd6e384bbf4353ebfabc4 Mon Sep 17 00:00:00 2001 From: xream Date: Tue, 9 Apr 2024 20:49:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=B9=B6=E5=9C=A8=E8=BF=9C=E7=A8=8B=E8=AE=A2=E9=98=85=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E6=97=B6=E8=AF=BB=E5=8F=96=E6=9C=80=E8=BF=91=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E6=88=90=E5=8A=9F=E7=9A=84=E7=BC=93=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 | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/backend/package.json b/backend/package.json index 2d032b1..94a2122 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.280", + "version": "2.14.281", "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 2e41b3c..12f4b2a 100644 --- a/backend/src/utils/download.js +++ b/backend/src/utils/download.js @@ -35,6 +35,9 @@ export default async function download(rawUrl, ua, timeout, proxy) { } } } + const customCacheKey = $arguments?.cacheKey + ? `#sub-store-cached-custom-${$arguments?.cacheKey}` + : undefined; // const downloadUrlMatch = url.match(/^\/api\/(file|module)\/(.+)/); // if (downloadUrlMatch) { @@ -116,10 +119,24 @@ export default async function download(rawUrl, ua, timeout, proxy) { } if (shouldCache) { resourceCache.set(id, body); + if (customCacheKey) { + $.write(body, customCacheKey); + } } result = body; } catch (e) { + if (customCacheKey) { + const cached = $.read(customCacheKey); + if (cached) { + $.info( + `无法下载 URL ${url}: ${ + e.message ?? e + }\n使用自定义缓存 ${$arguments?.cacheKey}`, + ); + return cached; + } + } throw new Error(`无法下载 URL ${url}: ${e.message ?? e}`); } }