Skip to content

Commit f38ec1e

Browse files
committed
feat: 手动设置的订阅流量信息会附加到订阅自己的流量信息之前
1 parent dea937d commit f38ec1e

File tree

3 files changed

+48
-54
lines changed

3 files changed

+48
-54
lines changed

backend/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store",
3-
"version": "2.14.420",
3+
"version": "2.14.422",
44
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
55
"main": "src/main.js",
66
"scripts": {

backend/src/restful/download.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ async function downloadSubscription(req, res) {
158158
proxy,
159159
noCache,
160160
});
161-
161+
let flowInfo;
162162
if (
163163
sub.source !== 'local' ||
164164
['localFirst', 'remoteFirst'].includes(sub.mergeSources)
@@ -193,7 +193,7 @@ async function downloadSubscription(req, res) {
193193
}
194194
if (!$arguments.noFlow) {
195195
// forward flow headers
196-
const flowInfo = await getFlowHeaders(
196+
flowInfo = await getFlowHeaders(
197197
$arguments?.insecure ? `${url}#insecure` : url,
198198
$arguments.flowUserAgent,
199199
undefined,
@@ -213,7 +213,10 @@ async function downloadSubscription(req, res) {
213213
}
214214
}
215215
if (sub.subUserinfo) {
216-
res.set('subscription-userinfo', sub.subUserinfo);
216+
res.set(
217+
'subscription-userinfo',
218+
[sub.subUserinfo, flowInfo].filter((i) => i).join('; '),
219+
);
217220
}
218221

219222
if (platform === 'JSON') {
@@ -358,6 +361,7 @@ async function downloadCollection(req, res) {
358361
const subnames = collection.subscriptions;
359362
if (subnames.length > 0) {
360363
const sub = findByName(allSubs, subnames[0]);
364+
let flowInfo;
361365
if (
362366
sub.source !== 'local' ||
363367
['localFirst', 'remoteFirst'].includes(sub.mergeSources)
@@ -391,7 +395,7 @@ async function downloadCollection(req, res) {
391395
}
392396
}
393397
if (!$arguments.noFlow) {
394-
const flowInfo = await getFlowHeaders(
398+
flowInfo = await getFlowHeaders(
395399
$arguments?.insecure ? `${url}#insecure` : url,
396400
$arguments.flowUserAgent,
397401
undefined,
@@ -411,7 +415,10 @@ async function downloadCollection(req, res) {
411415
}
412416
}
413417
if (sub.subUserinfo) {
414-
res.set('subscription-userinfo', sub.subUserinfo);
418+
res.set(
419+
'subscription-userinfo',
420+
[sub.subUserinfo, flowInfo].filter((i) => i).join('; '),
421+
);
415422
}
416423
}
417424

backend/src/restful/subscriptions.js

+35-48
Original file line numberDiff line numberDiff line change
@@ -125,66 +125,53 @@ async function getFlowInfo(req, res) {
125125
);
126126
return;
127127
}
128-
if (sub.subUserinfo) {
129-
try {
130-
const remainingDays = getRmainingDays({
131-
resetDay: $arguments.resetDay,
132-
startDate: $arguments.startDate,
133-
cycleDays: $arguments.cycleDays,
134-
});
135-
const result = {
136-
...parseFlowHeaders(sub.subUserinfo),
137-
};
138-
if (remainingDays != null) {
139-
result.remainingDays = remainingDays;
140-
}
141-
success(res, result);
142-
} catch (e) {
143-
$.error(
144-
`Failed to parse flow info for local subscription ${name}: ${
145-
e.message ?? e
146-
}`,
147-
);
148-
failed(
149-
res,
150-
new RequestInvalidError(
151-
'NO_FLOW_INFO',
152-
'N/A',
153-
`Failed to parse flow info`,
154-
),
155-
);
156-
}
157-
} else {
158-
const flowHeaders = await getFlowHeaders(
159-
$arguments?.insecure ? `${url}#insecure` : url,
160-
$arguments.flowUserAgent,
161-
undefined,
162-
sub.proxy,
163-
$arguments.flowUrl,
128+
const flowHeaders = await getFlowHeaders(
129+
$arguments?.insecure ? `${url}#insecure` : url,
130+
$arguments.flowUserAgent,
131+
undefined,
132+
sub.proxy,
133+
$arguments.flowUrl,
134+
);
135+
if (!flowHeaders && !sub.subUserinfo) {
136+
failed(
137+
res,
138+
new InternalServerError(
139+
'NO_FLOW_INFO',
140+
'No flow info',
141+
`Failed to fetch flow headers`,
142+
),
164143
);
165-
if (!flowHeaders) {
166-
failed(
167-
res,
168-
new InternalServerError(
169-
'NO_FLOW_INFO',
170-
'No flow info',
171-
`Failed to fetch flow headers`,
172-
),
173-
);
174-
return;
175-
}
144+
return;
145+
}
146+
try {
176147
const remainingDays = getRmainingDays({
177148
resetDay: $arguments.resetDay,
178149
startDate: $arguments.startDate,
179150
cycleDays: $arguments.cycleDays,
180151
});
181152
const result = {
182-
...parseFlowHeaders(flowHeaders),
153+
...parseFlowHeaders(
154+
[sub.subUserinfo, flowHeaders].filter((i) => i).join('; '),
155+
),
183156
};
184157
if (remainingDays != null) {
185158
result.remainingDays = remainingDays;
186159
}
187160
success(res, result);
161+
} catch (e) {
162+
$.error(
163+
`Failed to parse flow info for local subscription ${name}: ${
164+
e.message ?? e
165+
}`,
166+
);
167+
failed(
168+
res,
169+
new RequestInvalidError(
170+
'NO_FLOW_INFO',
171+
'N/A',
172+
`Failed to parse flow info`,
173+
),
174+
);
188175
}
189176
} catch (err) {
190177
failed(

0 commit comments

Comments
 (0)