diff --git a/backend/package.json b/backend/package.json index abaec5dde..51f26e499 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.420", + "version": "2.14.422", "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 168ed32d1..b2060f589 100644 --- a/backend/src/restful/download.js +++ b/backend/src/restful/download.js @@ -158,7 +158,7 @@ async function downloadSubscription(req, res) { proxy, noCache, }); - + let flowInfo; if ( sub.source !== 'local' || ['localFirst', 'remoteFirst'].includes(sub.mergeSources) @@ -193,7 +193,7 @@ async function downloadSubscription(req, res) { } if (!$arguments.noFlow) { // forward flow headers - const flowInfo = await getFlowHeaders( + flowInfo = await getFlowHeaders( $arguments?.insecure ? `${url}#insecure` : url, $arguments.flowUserAgent, undefined, @@ -213,7 +213,10 @@ async function downloadSubscription(req, res) { } } if (sub.subUserinfo) { - res.set('subscription-userinfo', sub.subUserinfo); + res.set( + 'subscription-userinfo', + [sub.subUserinfo, flowInfo].filter((i) => i).join('; '), + ); } if (platform === 'JSON') { @@ -358,6 +361,7 @@ async function downloadCollection(req, res) { const subnames = collection.subscriptions; if (subnames.length > 0) { const sub = findByName(allSubs, subnames[0]); + let flowInfo; if ( sub.source !== 'local' || ['localFirst', 'remoteFirst'].includes(sub.mergeSources) @@ -391,7 +395,7 @@ async function downloadCollection(req, res) { } } if (!$arguments.noFlow) { - const flowInfo = await getFlowHeaders( + flowInfo = await getFlowHeaders( $arguments?.insecure ? `${url}#insecure` : url, $arguments.flowUserAgent, undefined, @@ -411,7 +415,10 @@ async function downloadCollection(req, res) { } } if (sub.subUserinfo) { - res.set('subscription-userinfo', sub.subUserinfo); + res.set( + 'subscription-userinfo', + [sub.subUserinfo, flowInfo].filter((i) => i).join('; '), + ); } } diff --git a/backend/src/restful/subscriptions.js b/backend/src/restful/subscriptions.js index 0f066df05..083ec9ed3 100644 --- a/backend/src/restful/subscriptions.js +++ b/backend/src/restful/subscriptions.js @@ -125,66 +125,53 @@ async function getFlowInfo(req, res) { ); return; } - if (sub.subUserinfo) { - try { - 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}: ${ - 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, + const flowHeaders = await getFlowHeaders( + $arguments?.insecure ? `${url}#insecure` : url, + $arguments.flowUserAgent, + undefined, + sub.proxy, + $arguments.flowUrl, + ); + if (!flowHeaders && !sub.subUserinfo) { + failed( + res, + new InternalServerError( + 'NO_FLOW_INFO', + 'No flow info', + `Failed to fetch flow headers`, + ), ); - if (!flowHeaders) { - failed( - res, - new InternalServerError( - 'NO_FLOW_INFO', - 'No flow info', - `Failed to fetch flow headers`, - ), - ); - return; - } + return; + } + try { const remainingDays = getRmainingDays({ resetDay: $arguments.resetDay, startDate: $arguments.startDate, cycleDays: $arguments.cycleDays, }); const result = { - ...parseFlowHeaders(flowHeaders), + ...parseFlowHeaders( + [sub.subUserinfo, flowHeaders].filter((i) => i).join('; '), + ), }; if (remainingDays != null) { result.remainingDays = remainingDays; } 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) { failed(