mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-28 07:24:12 +00:00
feat: 订阅流量信息还原为 profile-web-page-url 响应头, 避免某些客户端出现异常
This commit is contained in:
4 files changed
+71
-24
No files matched your search
@@ -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": {
|
||||
|
||||
@@ -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') {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user