Skip to content

Commit

Permalink
feat: 手动设置流量信息时, 支持使用链接. 此时使用响应内容
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Dec 22, 2024
1 parent 0069b0c commit 837667e
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 5 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.446",
"version": "2.14.447",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
44 changes: 42 additions & 2 deletions backend/src/restful/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,29 @@ async function downloadSubscription(req, res) {
}
}
if (sub.subUserinfo) {
let subUserInfo;
if (/^https?:\/\//.test(sub.subUserinfo)) {
try {
subUserInfo = await getFlowHeaders(
undefined,
undefined,
undefined,
proxy || sub.proxy,
sub.subUserinfo,
);
} catch (e) {
$.error(
`订阅 ${name} 使用自定义流量链接 ${
sub.subUserinfo
} 获取流量信息时发生错误: ${JSON.stringify(e)}`,
);
}
} else {
subUserInfo = sub.subUserinfo;
}
res.set(
'subscription-userinfo',
[sub.subUserinfo, flowInfo].filter((i) => i).join('; '),
[subUserInfo, flowInfo].filter((i) => i).join('; '),
);
}

Expand Down Expand Up @@ -415,9 +435,29 @@ async function downloadCollection(req, res) {
}
}
if (sub.subUserinfo) {
let subUserInfo;
if (/^https?:\/\//.test(sub.subUserinfo)) {
try {
subUserInfo = await getFlowHeaders(
undefined,
undefined,
undefined,
proxy || sub.proxy,
sub.subUserinfo,
);
} catch (e) {
$.error(
`组合订阅 ${name} 使用自定义流量链接 ${
sub.subUserinfo
} 获取流量信息时发生错误: ${JSON.stringify(e)}`,
);
}
} else {
subUserInfo = sub.subUserinfo;
}
res.set(
'subscription-userinfo',
[sub.subUserinfo, flowInfo].filter((i) => i).join('; '),
[subUserInfo, flowInfo].filter((i) => i).join('; '),
);
}
}
Expand Down
44 changes: 42 additions & 2 deletions backend/src/restful/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,29 @@ async function getFlowInfo(req, res) {
!['localFirst', 'remoteFirst'].includes(sub.mergeSources)
) {
if (sub.subUserinfo) {
let subUserInfo;
if (/^https?:\/\//.test(sub.subUserinfo)) {
try {
subUserInfo = await getFlowHeaders(
undefined,
undefined,
undefined,
sub.proxy,
sub.subUserinfo,
);
} catch (e) {
$.error(
`订阅 ${name} 使用自定义流量链接 ${
sub.subUserinfo
} 获取流量信息时发生错误: ${JSON.stringify(e)}`,
);
}
} else {
subUserInfo = sub.subUserinfo;
}
try {
success(res, {
...parseFlowHeaders(sub.subUserinfo),
...parseFlowHeaders(subUserInfo),
});
} catch (e) {
$.error(
Expand Down Expand Up @@ -149,9 +169,29 @@ async function getFlowInfo(req, res) {
startDate: $arguments.startDate,
cycleDays: $arguments.cycleDays,
});
let subUserInfo;
if (/^https?:\/\//.test(sub.subUserinfo)) {
try {
subUserInfo = await getFlowHeaders(
undefined,
undefined,
undefined,
sub.proxy,
sub.subUserinfo,
);
} catch (e) {
$.error(
`订阅 ${name} 使用自定义流量链接 ${
sub.subUserinfo
} 获取流量信息时发生错误: ${JSON.stringify(e)}`,
);
}
} else {
subUserInfo = sub.subUserinfo;
}
const result = {
...parseFlowHeaders(
[sub.subUserinfo, flowHeaders].filter((i) => i).join('; '),
[subUserInfo, flowHeaders].filter((i) => i).join('; '),
),
};
if (remainingDays != null) {
Expand Down
3 changes: 3 additions & 0 deletions backend/src/utils/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ export async function getFlowHeaders(
flowInfo = getFlowField(headers);
}
}
if (flowInfo) {
flowInfo = flowInfo.trim();
}
if (flowInfo) {
headersResourceCache.set(id, flowInfo);
}
Expand Down

0 comments on commit 837667e

Please sign in to comment.