Skip to content

Commit

Permalink
feat: 支持更多的 subscription-userinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Nov 12, 2024
1 parent cc58a55 commit f4639d9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 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.415",
"version": "2.14.416",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
36 changes: 22 additions & 14 deletions backend/src/restful/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,18 @@ async function getFlowInfo(req, res) {
}
if (sub.subUserinfo) {
try {
success(res, {
...parseFlowHeaders(sub.subUserinfo),
remainingDays: getRmainingDays({
resetDay: $arguments.resetDay,
startDate: $arguments.startDate,
cycleDays: $arguments.cycleDays,
}),
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}: ${
Expand Down Expand Up @@ -169,14 +173,18 @@ async function getFlowInfo(req, res) {
);
return;
}
success(res, {
...parseFlowHeaders(flowHeaders),
remainingDays: getRmainingDays({
resetDay: $arguments.resetDay,
startDate: $arguments.startDate,
cycleDays: $arguments.cycleDays,
}),
const remainingDays = getRmainingDays({
resetDay: $arguments.resetDay,
startDate: $arguments.startDate,
cycleDays: $arguments.cycleDays,
});
const result = {
...parseFlowHeaders(flowHeaders),
};
if (remainingDays != null) {
result.remainingDays = remainingDays;
}
success(res, result);
}
} catch (err) {
failed(
Expand Down
17 changes: 16 additions & 1 deletion backend/src/utils/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,23 @@ export function parseFlowHeaders(flowHeaders) {
? Number(expireMatch[1] + expireMatch[2])
: undefined;

return { expires, total, usage: { upload, download } };
const remainingDaysMatch = flowHeaders.match(/reset_day=([0-9]+)/);
const remainingDays = remainingDaysMatch
? Number(remainingDaysMatch[1])
: undefined;

const appUrlMatch = flowHeaders.match(/app_url=(.*?)\s*?(;|$)/);
const appUrl = appUrlMatch ? appUrlMatch[1] : undefined;

return {
expires,
total,
usage: { upload, download },
remainingDays,
appUrl,
};
}

export function flowTransfer(flow, unit = 'B') {
const unitList = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
let unitIndex = unitList.indexOf(unit);
Expand Down

0 comments on commit f4639d9

Please sign in to comment.