feat: Clash 订阅仅缓存 proxies 数据

This commit is contained in:
xream 2024-12-27 11:54:38 +08:00
parent fa6472b1c1
commit 35dd4f31fc
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
2 changed files with 13 additions and 2 deletions

View File

@ -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": {

View File

@ -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();
@ -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 } : {}),
@ -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;