diff --git a/backend/package.json b/backend/package.json index 76ef79ce..0e2d03d9 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.20.69", + "version": "2.20.70", "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 60b29ecf..65e031d6 100644 --- a/backend/src/restful/download.js +++ b/backend/src/restful/download.js @@ -261,10 +261,19 @@ async function downloadSubscription(req, res) { $arguments.flowUrl, ); if (flowInfo) { - res.set( - 'subscription-userinfo', - normalizeFlowHeader(flowInfo), - ); + const headers = normalizeFlowHeader(flowInfo, true); + if (headers?.['subscription-userinfo']) { + res.set( + 'subscription-userinfo', + headers['subscription-userinfo'], + ); + } + if (headers?.['profile-web-page-url']) { + res.set( + 'profile-web-page-url', + headers['profile-web-page-url'], + ); + } } } } catch (err) { @@ -296,12 +305,23 @@ async function downloadSubscription(req, res) { } else { subUserInfo = sub.subUserinfo; } - res.set( - 'subscription-userinfo', - normalizeFlowHeader( - [subUserInfo, flowInfo].filter((i) => i).join(';'), - ), + + const headers = normalizeFlowHeader( + [subUserInfo, flowInfo].filter((i) => i).join(';'), + true, ); + if (headers?.['subscription-userinfo']) { + res.set( + 'subscription-userinfo', + headers['subscription-userinfo'], + ); + } + if (headers?.['profile-web-page-url']) { + res.set( + 'profile-web-page-url', + headers['profile-web-page-url'], + ); + } } if (platform === 'JSON') { @@ -573,10 +593,19 @@ async function downloadCollection(req, res) { .filter((i) => i) .join('; '); if (subUserInfo) { - res.set( - 'subscription-userinfo', - normalizeFlowHeader(subUserInfo), - ); + const headers = normalizeFlowHeader(subUserInfo, true); + if (headers?.['subscription-userinfo']) { + res.set( + 'subscription-userinfo', + headers['subscription-userinfo'], + ); + } + if (headers?.['profile-web-page-url']) { + res.set( + 'profile-web-page-url', + headers['profile-web-page-url'], + ); + } } if (platform === 'JSON') { if (resultFormat === 'nezha') { diff --git a/backend/src/restful/file.js b/backend/src/restful/file.js index de29fc8a..004b9cdf 100644 --- a/backend/src/restful/file.js +++ b/backend/src/restful/file.js @@ -156,10 +156,19 @@ async function getFile(req, res) { proxy || file.proxy, ); if (flowInfo) { - res.set( - 'subscription-userinfo', - normalizeFlowHeader(flowInfo), - ); + const headers = normalizeFlowHeader(flowInfo, true); + if (headers?.['subscription-userinfo']) { + res.set( + 'subscription-userinfo', + headers['subscription-userinfo'], + ); + } + if (headers?.['profile-web-page-url']) { + res.set( + 'profile-web-page-url', + headers['profile-web-page-url'], + ); + } } } } catch (err) { diff --git a/backend/src/utils/flow.js b/backend/src/utils/flow.js index 41745e17..99b80bb5 100644 --- a/backend/src/utils/flow.js +++ b/backend/src/utils/flow.js @@ -318,7 +318,7 @@ export function getRmainingDays(opt = {}) { } } -export function normalizeFlowHeader(flowHeaders) { +export function normalizeFlowHeader(flowHeaders, splitHeaders) { try { // 使用 Map 保持顺序并处理重复键 const kvMap = new Map(); @@ -366,11 +366,20 @@ export function normalizeFlowHeader(flowHeaders) { } } }); - - // 拼接标准化字符串 - return Array.from(kvMap.entries()) - .map(([k, v]) => `${k}=${encodeURIComponent(v)}`) // 重新编码保持兼容性 - .join('; '); + const headers = { + 'subscription-userinfo': '', + 'profile-web-page-url': '', + }; + kvMap.forEach((v, k) => { + if (splitHeaders && k === 'app_url') { + headers['profile-web-page-url'] = v; + } else { + headers['subscription-userinfo'] += `${k}=${encodeURIComponent( + v, + )}; `; + } + }); + return splitHeaders ? headers : headers['subscription-userinfo']; } catch (e) { $.error(`normalizeFlowHeader failed: ${e.message ?? e}`); return flowHeaders;