Skip to content

Commit f4cdc95

Browse files
committed
feat: 支持设置并在远程订阅失败时读取最近一次成功的缓存
1 parent 2a1c2eb commit f4cdc95

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store",
3-
"version": "2.14.280",
3+
"version": "2.14.281",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
55
"main": "src/main.js",
66
"scripts": {

backend/src/utils/download.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ export default async function download(rawUrl, ua, timeout, proxy) {
3535
}
3636
}
3737
}
38+
const customCacheKey = $arguments?.cacheKey
39+
? `#sub-store-cached-custom-${$arguments?.cacheKey}`
40+
: undefined;
3841

3942
// const downloadUrlMatch = url.match(/^\/api\/(file|module)\/(.+)/);
4043
// if (downloadUrlMatch) {
@@ -116,10 +119,24 @@ export default async function download(rawUrl, ua, timeout, proxy) {
116119
}
117120
if (shouldCache) {
118121
resourceCache.set(id, body);
122+
if (customCacheKey) {
123+
$.write(body, customCacheKey);
124+
}
119125
}
120126

121127
result = body;
122128
} catch (e) {
129+
if (customCacheKey) {
130+
const cached = $.read(customCacheKey);
131+
if (cached) {
132+
$.info(
133+
`无法下载 URL ${url}: ${
134+
e.message ?? e
135+
}\n使用自定义缓存 ${$arguments?.cacheKey}`,
136+
);
137+
return cached;
138+
}
139+
}
123140
throw new Error(`无法下载 URL ${url}: ${e.message ?? e}`);
124141
}
125142
}

0 commit comments

Comments
 (0)