mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-11 16:09:01 +08:00
feat: 支持设置并在远程订阅失败时读取最近一次成功的缓存
This commit is contained in:
parent
2a1c2eb9df
commit
f4cdc953e6
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sub-store",
|
"name": "sub-store",
|
||||||
"version": "2.14.280",
|
"version": "2.14.281",
|
||||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -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)\/(.+)/);
|
// const downloadUrlMatch = url.match(/^\/api\/(file|module)\/(.+)/);
|
||||||
// if (downloadUrlMatch) {
|
// if (downloadUrlMatch) {
|
||||||
@ -116,10 +119,24 @@ export default async function download(rawUrl, ua, timeout, proxy) {
|
|||||||
}
|
}
|
||||||
if (shouldCache) {
|
if (shouldCache) {
|
||||||
resourceCache.set(id, body);
|
resourceCache.set(id, body);
|
||||||
|
if (customCacheKey) {
|
||||||
|
$.write(body, customCacheKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = body;
|
result = body;
|
||||||
} catch (e) {
|
} 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}`);
|
throw new Error(`无法下载 URL ${url}: ${e.message ?? e}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user