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", "name": "sub-store",
"version": "2.14.452", "version": "2.14.453",
"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": {

View File

@ -11,6 +11,10 @@ import {
validCheck, validCheck,
} from '@/utils/flow'; } from '@/utils/flow';
import $ from '@/core/app'; 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(); 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}`, `Downloading...\nUser-Agent: ${userAgent}\nTimeout: ${requestTimeout}\nProxy: ${proxy}\nInsecure: ${!!insecure}\nURL: ${url}`,
); );
try { try {
const { body, headers, statusCode } = await http.get({ let { body, headers, statusCode } = await http.get({
url, url,
...(proxy ? { proxy } : {}), ...(proxy ? { proxy } : {}),
...(isLoon && proxy ? { node: proxy } : {}), ...(isLoon && proxy ? { node: proxy } : {}),
@ -193,6 +197,13 @@ export default async function download(
} }
if (body.replace(/\s/g, '').length === 0) if (body.replace(/\s/g, '').length === 0)
throw new Error(new Error('远程资源内容为空')); 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; let shouldCache = true;
if (cacheThreshold) { if (cacheThreshold) {
const size = body.length / 1024; const size = body.length / 1024;