mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-13 03:58:59 +08:00
feat: Clash 订阅仅缓存 proxies 数据
This commit is contained in:
parent
d9e4d814bb
commit
a3ec98caa9
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sub-store",
|
"name": "sub-store",
|
||||||
"version": "2.15.0",
|
"version": "2.15.1",
|
||||||
"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": {
|
||||||
|
@ -47,7 +47,16 @@ let resourceUrl = typeof $resourceUrl !== 'undefined' ? $resourceUrl : '';
|
|||||||
if ((!result || /^\s*$/.test(result)) && resourceUrl) {
|
if ((!result || /^\s*$/.test(result)) && resourceUrl) {
|
||||||
console.log(`解析器: 尝试从 ${resourceUrl} 获取订阅`);
|
console.log(`解析器: 尝试从 ${resourceUrl} 获取订阅`);
|
||||||
try {
|
try {
|
||||||
let raw = await download(resourceUrl, arg?.ua, arg?.timeout);
|
let raw = await download(
|
||||||
|
resourceUrl,
|
||||||
|
arg?.ua,
|
||||||
|
arg?.timeout,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
true,
|
||||||
|
);
|
||||||
let proxies = ProxyUtils.parse(raw);
|
let proxies = ProxyUtils.parse(raw);
|
||||||
result = ProxyUtils.produce(proxies, 'Loon', undefined, {
|
result = ProxyUtils.produce(proxies, 'Loon', undefined, {
|
||||||
'include-unsupported-proxy': arg?.includeUnsupportedProxy,
|
'include-unsupported-proxy': arg?.includeUnsupportedProxy,
|
||||||
|
@ -62,6 +62,7 @@ async function getFile(req, res) {
|
|||||||
mergeSources,
|
mergeSources,
|
||||||
ignoreFailedRemoteFile,
|
ignoreFailedRemoteFile,
|
||||||
proxy,
|
proxy,
|
||||||
|
noCache,
|
||||||
} = req.query;
|
} = req.query;
|
||||||
let $options = {};
|
let $options = {};
|
||||||
if (req.query.$options) {
|
if (req.query.$options) {
|
||||||
@ -113,6 +114,9 @@ async function getFile(req, res) {
|
|||||||
ignoreFailedRemoteFile = decodeURIComponent(ignoreFailedRemoteFile);
|
ignoreFailedRemoteFile = decodeURIComponent(ignoreFailedRemoteFile);
|
||||||
$.info(`指定忽略失败的远程文件: ${ignoreFailedRemoteFile}`);
|
$.info(`指定忽略失败的远程文件: ${ignoreFailedRemoteFile}`);
|
||||||
}
|
}
|
||||||
|
if (noCache) {
|
||||||
|
$.info(`指定不使用缓存: ${noCache}`);
|
||||||
|
}
|
||||||
|
|
||||||
const allFiles = $.read(FILES_KEY);
|
const allFiles = $.read(FILES_KEY);
|
||||||
const file = findByName(allFiles, name);
|
const file = findByName(allFiles, name);
|
||||||
@ -128,6 +132,7 @@ async function getFile(req, res) {
|
|||||||
ignoreFailedRemoteFile,
|
ignoreFailedRemoteFile,
|
||||||
$options,
|
$options,
|
||||||
proxy,
|
proxy,
|
||||||
|
noCache,
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -114,6 +114,10 @@ async function compareSub(req, res) {
|
|||||||
sub.ua,
|
sub.ua,
|
||||||
undefined,
|
undefined,
|
||||||
sub.proxy,
|
sub.proxy,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errors[url] = err;
|
errors[url] = err;
|
||||||
@ -219,6 +223,10 @@ async function compareCollection(req, res) {
|
|||||||
sub.ua,
|
sub.ua,
|
||||||
undefined,
|
undefined,
|
||||||
sub.proxy,
|
sub.proxy,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errors[url] = err;
|
errors[url] = err;
|
||||||
|
@ -74,6 +74,7 @@ async function produceArtifact({
|
|||||||
undefined,
|
undefined,
|
||||||
awaitCustomCache,
|
awaitCustomCache,
|
||||||
noCache,
|
noCache,
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errors[url] = err;
|
errors[url] = err;
|
||||||
@ -122,6 +123,7 @@ async function produceArtifact({
|
|||||||
undefined,
|
undefined,
|
||||||
awaitCustomCache,
|
awaitCustomCache,
|
||||||
noCache,
|
noCache,
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errors[url] = err;
|
errors[url] = err;
|
||||||
@ -243,6 +245,7 @@ async function produceArtifact({
|
|||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
noCache,
|
noCache,
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errors[url] = err;
|
errors[url] = err;
|
||||||
|
@ -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();
|
||||||
|
|
||||||
@ -22,6 +26,7 @@ export default async function download(
|
|||||||
skipCustomCache,
|
skipCustomCache,
|
||||||
awaitCustomCache,
|
awaitCustomCache,
|
||||||
noCache,
|
noCache,
|
||||||
|
preprocess,
|
||||||
) {
|
) {
|
||||||
let $arguments = {};
|
let $arguments = {};
|
||||||
let url = rawUrl.replace(/#noFlow$/, '');
|
let url = rawUrl.replace(/#noFlow$/, '');
|
||||||
@ -87,6 +92,9 @@ export default async function download(
|
|||||||
timeout,
|
timeout,
|
||||||
proxy,
|
proxy,
|
||||||
true,
|
true,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
preprocess,
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
$.error(
|
$.error(
|
||||||
@ -107,6 +115,9 @@ export default async function download(
|
|||||||
timeout,
|
timeout,
|
||||||
proxy,
|
proxy,
|
||||||
true,
|
true,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
preprocess,
|
||||||
).catch((e) => {
|
).catch((e) => {
|
||||||
$.error(
|
$.error(
|
||||||
`乐观缓存: URL ${url} 异步更新缓存发生错误 ${
|
`乐观缓存: URL ${url} 异步更新缓存发生错误 ${
|
||||||
@ -169,10 +180,10 @@ export default async function download(
|
|||||||
: { insecure: true }
|
: { insecure: true }
|
||||||
: undefined;
|
: undefined;
|
||||||
$.info(
|
$.info(
|
||||||
`Downloading...\nUser-Agent: ${userAgent}\nTimeout: ${requestTimeout}\nProxy: ${proxy}\nInsecure: ${!!insecure}\nURL: ${url}`,
|
`Downloading...\nUser-Agent: ${userAgent}\nTimeout: ${requestTimeout}\nProxy: ${proxy}\nInsecure: ${!!insecure}\nPreprocess: ${preprocess}\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 +204,15 @@ 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('远程资源内容为空'));
|
||||||
|
if (preprocess) {
|
||||||
|
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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user