From ca65e4209e344a9229fabd83dbc2bfadb5277c86 Mon Sep 17 00:00:00 2001 From: xream Date: Tue, 12 Mar 2024 01:17:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E8=AE=A2=E9=98=85=E6=B5=81=E9=87=8F=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/download.js | 6 +++ backend/src/restful/subscriptions.js | 71 +++++++++++++++++----------- 3 files changed, 51 insertions(+), 28 deletions(-) diff --git a/backend/package.json b/backend/package.json index 6405d7c..c0d80ec 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.248", + "version": "2.14.249", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/restful/download.js b/backend/src/restful/download.js index 7ba2d25..2fce1a7 100644 --- a/backend/src/restful/download.js +++ b/backend/src/restful/download.js @@ -124,6 +124,9 @@ async function downloadSubscription(req, res) { ); } } + if (sub.subUserinfo) { + res.set('subscription-userinfo', sub.subUserinfo); + } if (platform === 'JSON') { res.set('Content-Type', 'application/json;charset=utf-8').send( @@ -253,6 +256,9 @@ async function downloadCollection(req, res) { ); } } + if (sub.subUserinfo) { + res.set('subscription-userinfo', sub.subUserinfo); + } } if (platform === 'JSON') { diff --git a/backend/src/restful/subscriptions.js b/backend/src/restful/subscriptions.js index 001e441..af3d367 100644 --- a/backend/src/restful/subscriptions.js +++ b/backend/src/restful/subscriptions.js @@ -51,14 +51,20 @@ async function getFlowInfo(req, res) { sub.source === 'local' && !['localFirst', 'remoteFirst'].includes(sub.mergeSources) ) { - failed( - res, - new RequestInvalidError( - 'NO_FLOW_INFO', - 'N/A', - `Local subscription ${name} has no flow information!`, - ), - ); + if (sub.subUserinfo) { + success(res, { + ...parseFlowHeaders(sub.subUserinfo), + }); + } else { + failed( + res, + new RequestInvalidError( + 'NO_FLOW_INFO', + 'N/A', + `Local subscription ${name} has no flow information!`, + ), + ); + } return; } try { @@ -97,26 +103,37 @@ async function getFlowInfo(req, res) { ); return; } - const flowHeaders = await getFlowHeaders(url); - if (!flowHeaders) { - failed( - res, - new InternalServerError( - 'NO_FLOW_INFO', - 'No flow info', - `Failed to fetch flow headers`, - ), - ); - return; + if (sub.subUserinfo) { + success(res, { + ...parseFlowHeaders(sub.subUserinfo), + remainingDays: getRmainingDays({ + resetDay: $arguments.resetDay, + startDate: $arguments.startDate, + cycleDays: $arguments.cycleDays, + }), + }); + } else { + const flowHeaders = await getFlowHeaders(url); + if (!flowHeaders) { + failed( + res, + new InternalServerError( + 'NO_FLOW_INFO', + 'No flow info', + `Failed to fetch flow headers`, + ), + ); + return; + } + success(res, { + ...parseFlowHeaders(flowHeaders), + remainingDays: getRmainingDays({ + resetDay: $arguments.resetDay, + startDate: $arguments.startDate, + cycleDays: $arguments.cycleDays, + }), + }); } - success(res, { - ...parseFlowHeaders(flowHeaders), - remainingDays: getRmainingDays({ - resetDay: $arguments.resetDay, - startDate: $arguments.startDate, - cycleDays: $arguments.cycleDays, - }), - }); } catch (err) { failed( res,