mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-07-30 09:11:59 +08:00
feat: 手动设置的订阅流量信息会附加到订阅自己的流量信息之前
This commit is contained in:
parent
dea937df66
commit
bc1247efaf
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.14.420",
|
||||
"version": "2.14.422",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
|
@ -158,7 +158,7 @@ async function downloadSubscription(req, res) {
|
||||
proxy,
|
||||
noCache,
|
||||
});
|
||||
|
||||
let flowInfo;
|
||||
if (
|
||||
sub.source !== 'local' ||
|
||||
['localFirst', 'remoteFirst'].includes(sub.mergeSources)
|
||||
@ -193,7 +193,7 @@ async function downloadSubscription(req, res) {
|
||||
}
|
||||
if (!$arguments.noFlow) {
|
||||
// forward flow headers
|
||||
const flowInfo = await getFlowHeaders(
|
||||
flowInfo = await getFlowHeaders(
|
||||
$arguments?.insecure ? `${url}#insecure` : url,
|
||||
$arguments.flowUserAgent,
|
||||
undefined,
|
||||
@ -213,7 +213,10 @@ async function downloadSubscription(req, res) {
|
||||
}
|
||||
}
|
||||
if (sub.subUserinfo) {
|
||||
res.set('subscription-userinfo', sub.subUserinfo);
|
||||
res.set(
|
||||
'subscription-userinfo',
|
||||
[sub.subUserinfo, flowInfo].filter((i) => i).join('; '),
|
||||
);
|
||||
}
|
||||
|
||||
if (platform === 'JSON') {
|
||||
@ -358,6 +361,7 @@ async function downloadCollection(req, res) {
|
||||
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)
|
||||
@ -391,7 +395,7 @@ async function downloadCollection(req, res) {
|
||||
}
|
||||
}
|
||||
if (!$arguments.noFlow) {
|
||||
const flowInfo = await getFlowHeaders(
|
||||
flowInfo = await getFlowHeaders(
|
||||
$arguments?.insecure ? `${url}#insecure` : url,
|
||||
$arguments.flowUserAgent,
|
||||
undefined,
|
||||
@ -411,7 +415,10 @@ async function downloadCollection(req, res) {
|
||||
}
|
||||
}
|
||||
if (sub.subUserinfo) {
|
||||
res.set('subscription-userinfo', sub.subUserinfo);
|
||||
res.set(
|
||||
'subscription-userinfo',
|
||||
[sub.subUserinfo, flowInfo].filter((i) => i).join('; '),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,66 +125,53 @@ async function getFlowInfo(req, res) {
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (sub.subUserinfo) {
|
||||
try {
|
||||
const remainingDays = getRmainingDays({
|
||||
resetDay: $arguments.resetDay,
|
||||
startDate: $arguments.startDate,
|
||||
cycleDays: $arguments.cycleDays,
|
||||
});
|
||||
const result = {
|
||||
...parseFlowHeaders(sub.subUserinfo),
|
||||
};
|
||||
if (remainingDays != null) {
|
||||
result.remainingDays = remainingDays;
|
||||
}
|
||||
success(res, result);
|
||||
} catch (e) {
|
||||
$.error(
|
||||
`Failed to parse flow info for local subscription ${name}: ${
|
||||
e.message ?? e
|
||||
}`,
|
||||
);
|
||||
failed(
|
||||
res,
|
||||
new RequestInvalidError(
|
||||
'NO_FLOW_INFO',
|
||||
'N/A',
|
||||
`Failed to parse flow info`,
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
const flowHeaders = await getFlowHeaders(
|
||||
$arguments?.insecure ? `${url}#insecure` : url,
|
||||
$arguments.flowUserAgent,
|
||||
undefined,
|
||||
sub.proxy,
|
||||
$arguments.flowUrl,
|
||||
const flowHeaders = await getFlowHeaders(
|
||||
$arguments?.insecure ? `${url}#insecure` : url,
|
||||
$arguments.flowUserAgent,
|
||||
undefined,
|
||||
sub.proxy,
|
||||
$arguments.flowUrl,
|
||||
);
|
||||
if (!flowHeaders && !sub.subUserinfo) {
|
||||
failed(
|
||||
res,
|
||||
new InternalServerError(
|
||||
'NO_FLOW_INFO',
|
||||
'No flow info',
|
||||
`Failed to fetch flow headers`,
|
||||
),
|
||||
);
|
||||
if (!flowHeaders) {
|
||||
failed(
|
||||
res,
|
||||
new InternalServerError(
|
||||
'NO_FLOW_INFO',
|
||||
'No flow info',
|
||||
`Failed to fetch flow headers`,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const remainingDays = getRmainingDays({
|
||||
resetDay: $arguments.resetDay,
|
||||
startDate: $arguments.startDate,
|
||||
cycleDays: $arguments.cycleDays,
|
||||
});
|
||||
const result = {
|
||||
...parseFlowHeaders(flowHeaders),
|
||||
...parseFlowHeaders(
|
||||
[sub.subUserinfo, flowHeaders].filter((i) => i).join('; '),
|
||||
),
|
||||
};
|
||||
if (remainingDays != null) {
|
||||
result.remainingDays = remainingDays;
|
||||
}
|
||||
success(res, result);
|
||||
} catch (e) {
|
||||
$.error(
|
||||
`Failed to parse flow info for local subscription ${name}: ${
|
||||
e.message ?? e
|
||||
}`,
|
||||
);
|
||||
failed(
|
||||
res,
|
||||
new RequestInvalidError(
|
||||
'NO_FLOW_INFO',
|
||||
'N/A',
|
||||
`Failed to parse flow info`,
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (err) {
|
||||
failed(
|
||||
|
@ -205,7 +205,7 @@ export function parseFlowHeaders(flowHeaders) {
|
||||
: undefined;
|
||||
|
||||
const appUrlMatch = flowHeaders.match(/app_url=(.*?)\s*?(;|$)/);
|
||||
const appUrl = appUrlMatch ? appUrlMatch[1] : undefined;
|
||||
const appUrl = appUrlMatch ? decodeURIComponent(appUrlMatch[1]) : undefined;
|
||||
|
||||
const planNameMatch = flowHeaders.match(/plan_name=(.*?)\s*?(;|$)/);
|
||||
const planName = planNameMatch
|
||||
|
Loading…
x
Reference in New Issue
Block a user