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