Skip to content

Commit

Permalink
feat: Clash 订阅仅缓存 proxies 数据
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Dec 27, 2024
1 parent fa6472b commit 35dd4f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.452",
"version": "2.14.453",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
13 changes: 12 additions & 1 deletion backend/src/utils/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {
validCheck,
} from '@/utils/flow';
import $ from '@/core/app';
import PROXY_PREPROCESSORS from '@/core/proxy-utils/preprocessors';
const clashPreprocessor = PROXY_PREPROCESSORS.find(
(processor) => processor.name === 'Clash Pre-processor',
);

const tasks = new Map();

Expand Down Expand Up @@ -172,7 +176,7 @@ export default async function download(
`Downloading...\nUser-Agent: ${userAgent}\nTimeout: ${requestTimeout}\nProxy: ${proxy}\nInsecure: ${!!insecure}\nURL: ${url}`,
);
try {
const { body, headers, statusCode } = await http.get({
let { body, headers, statusCode } = await http.get({
url,
...(proxy ? { proxy } : {}),
...(isLoon && proxy ? { node: proxy } : {}),
Expand All @@ -193,6 +197,13 @@ export default async function download(
}
if (body.replace(/\s/g, '').length === 0)
throw new Error(new Error('远程资源内容为空'));
try {
if (clashPreprocessor.test(body)) {
body = clashPreprocessor.parse(body);
}
} catch (e) {
$.error(`Clash Pre-processor error: ${e}`);
}
let shouldCache = true;
if (cacheThreshold) {
const size = body.length / 1024;
Expand Down

0 comments on commit 35dd4f3

Please sign in to comment.