diff --git a/backend/package.json b/backend/package.json index 56088957..4e4bab16 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.24.14", + "version": "2.24.16", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "packageManager": "pnpm@11.0.9", diff --git a/backend/src/restful/download.js b/backend/src/restful/download.js index 80273653..e73a7c1f 100644 --- a/backend/src/restful/download.js +++ b/backend/src/restful/download.js @@ -145,6 +145,7 @@ async function downloadSubscription(req, res) { proxy, noCache, _fakeNode, + fakeSub: _fakeSub, } = req.query; const prettyYaml = req.query.prettyYaml ?? req.query['pretty-yaml']; @@ -188,6 +189,9 @@ async function downloadSubscription(req, res) { $.info(`URL 不是链接,视为本地订阅`); } } + if (_fakeSub) { + $.info(`使用假订阅, 不再通过单条订阅名称 ${name} 查询`); + } if (content) { $.info(`指定本地订阅: ${content}`); } @@ -232,13 +236,17 @@ async function downloadSubscription(req, res) { } const allSubs = $.read(SUBS_KEY); - const fakeSub = { + const fakeSub = _fakeNode ? { name: 'fakeNodeInfo', source: 'local', content: 'invalid share = ss, 1.0.0.1, 80, encrypt-method=aes-128-gcm, password=password', + } : { + name: 'fakeSub', + source: 'remote', + url: '', }; - const sub = _fakeNode ? fakeSub : findByName(allSubs, name); + const sub = (_fakeNode || _fakeSub) ? fakeSub : findByName(allSubs, name); if (sub) { try { const passThroughUA = sub.passThroughUA; @@ -270,8 +278,10 @@ async function downloadSubscription(req, res) { proxy, noCache, }; - if (_fakeNode) { - $.info(`返回假节点信息`); + if (_fakeNode || _fakeSub) { + if(_fakeNode) { + $.info(`返回假节点信息`); + } delete opt.name; opt.subscription = fakeSub; } diff --git a/backend/src/restful/parser.js b/backend/src/restful/parser.js index d5b1888b..e1ed307c 100644 --- a/backend/src/restful/parser.js +++ b/backend/src/restful/parser.js @@ -1,6 +1,7 @@ import { success, failed } from '@/restful/response'; import { ProxyUtils } from '@/core/proxy-utils'; import { RuleUtils } from '@/core/rule-utils'; +import download from '@/utils/download'; export default function register($app) { $app.route('/api/proxy/parse').post(proxy_parser); @@ -19,12 +20,18 @@ export default function register($app) { * client: string, 目标平台名称,见backend/src/core/proxy-utils/producers/index.js * */ -function proxy_parser(req, res) { - const { data, client, content, platform } = req.body; +async function proxy_parser(req, res) { var result = {}; try { - var proxies = ProxyUtils.parse(data ?? content); - var par_res = ProxyUtils.produce(proxies, client ?? platform); + const { data, client, content, platform, download: downloadOpts, type, produce: produceOpts } = req.body; + let raw; + if (downloadOpts) { + raw = await download(...downloadOpts); + } else { + raw = data ?? content + } + var proxies = ProxyUtils.parse(raw); + var par_res = ProxyUtils.produce(proxies, client ?? platform, type, produceOpts); result['par_res'] = par_res; } catch (err) { failed(res, err); @@ -39,9 +46,9 @@ function proxy_parser(req, res) { * client: string, 目标平台名称,具体见backend/src/core/rule-utils/producers.js */ function rule_parser(req, res) { - const { data, client, content, platform } = req.body; var result = {}; try { + const { data, client, content, platform } = req.body; const rules = RuleUtils.parse(data ?? content); var par_res = RuleUtils.produce(rules, client ?? platform); result['par_res'] = par_res;