feat: 支持自定义订阅流量信息

This commit is contained in:
xream 2024-03-12 01:17:56 +08:00
parent 53bb4866e7
commit ca65e4209e
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
3 changed files with 51 additions and 28 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "sub-store", "name": "sub-store",
"version": "2.14.248", "version": "2.14.249",
"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": {

View File

@ -124,6 +124,9 @@ async function downloadSubscription(req, res) {
); );
} }
} }
if (sub.subUserinfo) {
res.set('subscription-userinfo', sub.subUserinfo);
}
if (platform === 'JSON') { if (platform === 'JSON') {
res.set('Content-Type', 'application/json;charset=utf-8').send( res.set('Content-Type', 'application/json;charset=utf-8').send(
@ -253,6 +256,9 @@ async function downloadCollection(req, res) {
); );
} }
} }
if (sub.subUserinfo) {
res.set('subscription-userinfo', sub.subUserinfo);
}
} }
if (platform === 'JSON') { if (platform === 'JSON') {

View File

@ -51,14 +51,20 @@ async function getFlowInfo(req, res) {
sub.source === 'local' && sub.source === 'local' &&
!['localFirst', 'remoteFirst'].includes(sub.mergeSources) !['localFirst', 'remoteFirst'].includes(sub.mergeSources)
) { ) {
failed( if (sub.subUserinfo) {
res, success(res, {
new RequestInvalidError( ...parseFlowHeaders(sub.subUserinfo),
'NO_FLOW_INFO', });
'N/A', } else {
`Local subscription ${name} has no flow information!`, failed(
), res,
); new RequestInvalidError(
'NO_FLOW_INFO',
'N/A',
`Local subscription ${name} has no flow information!`,
),
);
}
return; return;
} }
try { try {
@ -97,26 +103,37 @@ async function getFlowInfo(req, res) {
); );
return; return;
} }
const flowHeaders = await getFlowHeaders(url); if (sub.subUserinfo) {
if (!flowHeaders) { success(res, {
failed( ...parseFlowHeaders(sub.subUserinfo),
res, remainingDays: getRmainingDays({
new InternalServerError( resetDay: $arguments.resetDay,
'NO_FLOW_INFO', startDate: $arguments.startDate,
'No flow info', cycleDays: $arguments.cycleDays,
`Failed to fetch flow headers`, }),
), });
); } else {
return; const flowHeaders = await getFlowHeaders(url);
if (!flowHeaders) {
failed(
res,
new InternalServerError(
'NO_FLOW_INFO',
'No flow info',
`Failed to fetch flow headers`,
),
);
return;
}
success(res, {
...parseFlowHeaders(flowHeaders),
remainingDays: getRmainingDays({
resetDay: $arguments.resetDay,
startDate: $arguments.startDate,
cycleDays: $arguments.cycleDays,
}),
});
} }
success(res, {
...parseFlowHeaders(flowHeaders),
remainingDays: getRmainingDays({
resetDay: $arguments.resetDay,
startDate: $arguments.startDate,
cycleDays: $arguments.cycleDays,
}),
});
} catch (err) { } catch (err) {
failed( failed(
res, res,