Skip to content

Commit e72a394

Browse files
committed
feat: 单条订阅链接参数新增 fakeSub, 此时不再使用 name 查询; proxy_parser 优化, 支持下载
1 parent 99d15b9 commit e72a394

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store",
3-
"version": "2.24.14",
3+
"version": "2.24.16",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
55
"main": "src/main.js",
66
"packageManager": "pnpm@11.0.9",

backend/src/restful/download.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ async function downloadSubscription(req, res) {
145145
proxy,
146146
noCache,
147147
_fakeNode,
148+
fakeSub: _fakeSub,
148149
} = req.query;
149150
const prettyYaml = req.query.prettyYaml ?? req.query['pretty-yaml'];
150151

@@ -188,6 +189,9 @@ async function downloadSubscription(req, res) {
188189
$.info(`URL 不是链接,视为本地订阅`);
189190
}
190191
}
192+
if (_fakeSub) {
193+
$.info(`使用假订阅, 不再通过单条订阅名称 ${name} 查询`);
194+
}
191195
if (content) {
192196
$.info(`指定本地订阅: ${content}`);
193197
}
@@ -232,13 +236,17 @@ async function downloadSubscription(req, res) {
232236
}
233237

234238
const allSubs = $.read(SUBS_KEY);
235-
const fakeSub = {
239+
const fakeSub = _fakeNode ? {
236240
name: 'fakeNodeInfo',
237241
source: 'local',
238242
content:
239243
'invalid share = ss, 1.0.0.1, 80, encrypt-method=aes-128-gcm, password=password',
244+
} : {
245+
name: 'fakeSub',
246+
source: 'remote',
247+
url: '',
240248
};
241-
const sub = _fakeNode ? fakeSub : findByName(allSubs, name);
249+
const sub = (_fakeNode || _fakeSub) ? fakeSub : findByName(allSubs, name);
242250
if (sub) {
243251
try {
244252
const passThroughUA = sub.passThroughUA;
@@ -270,8 +278,10 @@ async function downloadSubscription(req, res) {
270278
proxy,
271279
noCache,
272280
};
273-
if (_fakeNode) {
274-
$.info(`返回假节点信息`);
281+
if (_fakeNode || _fakeSub) {
282+
if(_fakeNode) {
283+
$.info(`返回假节点信息`);
284+
}
275285
delete opt.name;
276286
opt.subscription = fakeSub;
277287
}

backend/src/restful/parser.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { success, failed } from '@/restful/response';
22
import { ProxyUtils } from '@/core/proxy-utils';
33
import { RuleUtils } from '@/core/rule-utils';
4+
import download from '@/utils/download';
45

56
export default function register($app) {
67
$app.route('/api/proxy/parse').post(proxy_parser);
@@ -19,12 +20,18 @@ export default function register($app) {
1920
* client: string, 目标平台名称,见backend/src/core/proxy-utils/producers/index.js
2021
*
2122
*/
22-
function proxy_parser(req, res) {
23-
const { data, client, content, platform } = req.body;
23+
async function proxy_parser(req, res) {
2424
var result = {};
2525
try {
26-
var proxies = ProxyUtils.parse(data ?? content);
27-
var par_res = ProxyUtils.produce(proxies, client ?? platform);
26+
const { data, client, content, platform, download: downloadOpts, type, produce: produceOpts } = req.body;
27+
let raw;
28+
if (downloadOpts) {
29+
raw = await download(...downloadOpts);
30+
} else {
31+
raw = data ?? content
32+
}
33+
var proxies = ProxyUtils.parse(raw);
34+
var par_res = ProxyUtils.produce(proxies, client ?? platform, type, produceOpts);
2835
result['par_res'] = par_res;
2936
} catch (err) {
3037
failed(res, err);
@@ -39,9 +46,9 @@ function proxy_parser(req, res) {
3946
* client: string, 目标平台名称,具体见backend/src/core/rule-utils/producers.js
4047
*/
4148
function rule_parser(req, res) {
42-
const { data, client, content, platform } = req.body;
4349
var result = {};
4450
try {
51+
const { data, client, content, platform } = req.body;
4552
const rules = RuleUtils.parse(data ?? content);
4653
var par_res = RuleUtils.produce(rules, client ?? platform);
4754
result['par_res'] = par_res;

0 commit comments

Comments
 (0)