Skip to content

Commit

Permalink
feat: 组合订阅支持手动设置流量信息. 支持使用链接. 此时使用响应内容
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Dec 23, 2024
1 parent 33e5aec commit 38eccca
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.448",
"version": "2.14.449",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
42 changes: 33 additions & 9 deletions backend/src/restful/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,12 @@ async function downloadCollection(req, res) {
proxy,
noCache,
});

let subUserInfoOfSub;
// forward flow header from the first subscription in this collection
const allSubs = $.read(SUBS_KEY);
const subnames = collection.subscriptions;
if (subnames.length > 0) {
const sub = findByName(allSubs, subnames[0]);
let flowInfo;
if (
sub.source !== 'local' ||
['localFirst', 'remoteFirst'].includes(sub.mergeSources)
Expand Down Expand Up @@ -415,16 +414,13 @@ async function downloadCollection(req, res) {
}
}
if (!$arguments.noFlow) {
flowInfo = await getFlowHeaders(
subUserInfoOfSub = await getFlowHeaders(
$arguments?.insecure ? `${url}#insecure` : url,
$arguments.flowUserAgent,
undefined,
proxy || sub.proxy || collection.proxy,
$arguments.flowUrl,
);
if (flowInfo) {
res.set('subscription-userinfo', flowInfo);
}
}
} catch (err) {
$.error(
Expand Down Expand Up @@ -455,12 +451,40 @@ async function downloadCollection(req, res) {
} else {
subUserInfo = sub.subUserinfo;
}
res.set(
'subscription-userinfo',
[subUserInfo, flowInfo].filter((i) => i).join('; '),
subUserInfoOfSub = [subUserInfo, subUserInfoOfSub]
.filter((i) => i)
.join('; ');
}
}

$.info(`组合订阅 ${name} 透传的的流量信息: ${subUserInfoOfSub}`);

let subUserInfoOfCol;
if (/^https?:\/\//.test(collection.subUserinfo)) {
try {
subUserInfoOfCol = await getFlowHeaders(
undefined,
undefined,
undefined,
proxy || collection.proxy,
collection.subUserinfo,
);
} catch (e) {
$.error(
`组合订阅 ${name} 使用自定义流量链接 ${
collection.subUserinfo
} 获取流量信息时发生错误: ${JSON.stringify(e)}`,
);
}
} else {
subUserInfoOfCol = collection.subUserinfo;
}
res.set(
'subscription-userinfo',
[subUserInfoOfCol, subUserInfoOfSub]
.filter((i) => i)
.join('; '),
);

if (platform === 'JSON') {
if (resultFormat === 'nezha') {
Expand Down

0 comments on commit 38eccca

Please sign in to comment.