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