From f4639d9a348b37329872394ebd99b4eb2713db91 Mon Sep 17 00:00:00 2001 From: xream Date: Tue, 12 Nov 2024 22:06:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E7=9A=84=20subscription-userinfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/subscriptions.js | 36 +++++++++++++++++----------- backend/src/utils/flow.js | 17 ++++++++++++- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/backend/package.json b/backend/package.json index 06e8fccbd..f1e8a5bf5 100644 --- a/backend/package.json +++ b/backend/package.json @@ -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": { diff --git a/backend/src/restful/subscriptions.js b/backend/src/restful/subscriptions.js index 6cd2503cf..0f066df05 100644 --- a/backend/src/restful/subscriptions.js +++ b/backend/src/restful/subscriptions.js @@ -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}: ${ @@ -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( diff --git a/backend/src/utils/flow.js b/backend/src/utils/flow.js index e3ea6c8dd..fc7a1fef0 100644 --- a/backend/src/utils/flow.js +++ b/backend/src/utils/flow.js @@ -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);