feat: 支持更多的 subscription-userinfo

This commit is contained in:
xream 2024-11-12 22:06:22 +08:00
parent cc58a5541e
commit f4639d9a34
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
3 changed files with 39 additions and 16 deletions

View File

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

@ -127,14 +127,18 @@ async function getFlowInfo(req, res) {
} }
if (sub.subUserinfo) { if (sub.subUserinfo) {
try { try {
success(res, { const remainingDays = getRmainingDays({
...parseFlowHeaders(sub.subUserinfo), resetDay: $arguments.resetDay,
remainingDays: getRmainingDays({ startDate: $arguments.startDate,
resetDay: $arguments.resetDay, cycleDays: $arguments.cycleDays,
startDate: $arguments.startDate,
cycleDays: $arguments.cycleDays,
}),
}); });
const result = {
...parseFlowHeaders(sub.subUserinfo),
};
if (remainingDays != null) {
result.remainingDays = remainingDays;
}
success(res, result);
} catch (e) { } catch (e) {
$.error( $.error(
`Failed to parse flow info for local subscription ${name}: ${ `Failed to parse flow info for local subscription ${name}: ${
@ -169,14 +173,18 @@ async function getFlowInfo(req, res) {
); );
return; return;
} }
success(res, { const remainingDays = getRmainingDays({
...parseFlowHeaders(flowHeaders), resetDay: $arguments.resetDay,
remainingDays: getRmainingDays({ startDate: $arguments.startDate,
resetDay: $arguments.resetDay, cycleDays: $arguments.cycleDays,
startDate: $arguments.startDate,
cycleDays: $arguments.cycleDays,
}),
}); });
const result = {
...parseFlowHeaders(flowHeaders),
};
if (remainingDays != null) {
result.remainingDays = remainingDays;
}
success(res, result);
} }
} catch (err) { } catch (err) {
failed( failed(

View File

@ -190,8 +190,23 @@ export function parseFlowHeaders(flowHeaders) {
? Number(expireMatch[1] + expireMatch[2]) ? Number(expireMatch[1] + expireMatch[2])
: undefined; : 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') { export function flowTransfer(flow, unit = 'B') {
const unitList = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; const unitList = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
let unitIndex = unitList.indexOf(unit); let unitIndex = unitList.indexOf(unit);