mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-12 04:29:00 +08:00
fix: 修复订阅流量传递
This commit is contained in:
parent
09495fa607
commit
53bb4866e7
@ -77,13 +77,45 @@ async function downloadSubscription(req, res) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (sub.source !== 'local' || url) {
|
if (
|
||||||
|
sub.source !== 'local' ||
|
||||||
|
['localFirst', 'remoteFirst'].includes(sub.mergeSources) ||
|
||||||
|
url
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
|
url = `${url || sub.url}`
|
||||||
|
.split(/[\r\n]+/)
|
||||||
|
.map((i) => i.trim())
|
||||||
|
.filter((i) => i.length)?.[0];
|
||||||
|
|
||||||
|
let $arguments = {};
|
||||||
|
const rawArgs = url.split('#');
|
||||||
|
url = url.split('#')[0];
|
||||||
|
if (rawArgs.length > 1) {
|
||||||
|
try {
|
||||||
|
// 支持 `#${encodeURIComponent(JSON.stringify({arg1: "1"}))}`
|
||||||
|
$arguments = JSON.parse(
|
||||||
|
decodeURIComponent(rawArgs[1]),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
for (const pair of rawArgs[1].split('&')) {
|
||||||
|
const key = pair.split('=')[0];
|
||||||
|
const value = pair.split('=')[1];
|
||||||
|
// 部分兼容之前的逻辑 const value = pair.split('=')[1] || true;
|
||||||
|
$arguments[key] =
|
||||||
|
value == null || value === ''
|
||||||
|
? true
|
||||||
|
: decodeURIComponent(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$arguments.noFlow) {
|
||||||
// forward flow headers
|
// forward flow headers
|
||||||
const flowInfo = await getFlowHeaders(url || sub.url);
|
const flowInfo = await getFlowHeaders(url);
|
||||||
if (flowInfo) {
|
if (flowInfo) {
|
||||||
res.set('subscription-userinfo', flowInfo);
|
res.set('subscription-userinfo', flowInfo);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
$.error(
|
$.error(
|
||||||
`订阅 ${name} 获取流量信息时发生错误: ${JSON.stringify(
|
`订阅 ${name} 获取流量信息时发生错误: ${JSON.stringify(
|
||||||
@ -176,12 +208,43 @@ async function downloadCollection(req, res) {
|
|||||||
const subnames = collection.subscriptions;
|
const subnames = collection.subscriptions;
|
||||||
if (subnames.length > 0) {
|
if (subnames.length > 0) {
|
||||||
const sub = findByName(allSubs, subnames[0]);
|
const sub = findByName(allSubs, subnames[0]);
|
||||||
if (sub.source !== 'local') {
|
if (
|
||||||
|
sub.source !== 'local' ||
|
||||||
|
['localFirst', 'remoteFirst'].includes(sub.mergeSources)
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
const flowInfo = await getFlowHeaders(sub.url);
|
let url = `${sub.url}`
|
||||||
|
.split(/[\r\n]+/)
|
||||||
|
.map((i) => i.trim())
|
||||||
|
.filter((i) => i.length)?.[0];
|
||||||
|
|
||||||
|
let $arguments = {};
|
||||||
|
const rawArgs = url.split('#');
|
||||||
|
url = url.split('#')[0];
|
||||||
|
if (rawArgs.length > 1) {
|
||||||
|
try {
|
||||||
|
// 支持 `#${encodeURIComponent(JSON.stringify({arg1: "1"}))}`
|
||||||
|
$arguments = JSON.parse(
|
||||||
|
decodeURIComponent(rawArgs[1]),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
for (const pair of rawArgs[1].split('&')) {
|
||||||
|
const key = pair.split('=')[0];
|
||||||
|
const value = pair.split('=')[1];
|
||||||
|
// 部分兼容之前的逻辑 const value = pair.split('=')[1] || true;
|
||||||
|
$arguments[key] =
|
||||||
|
value == null || value === ''
|
||||||
|
? true
|
||||||
|
: decodeURIComponent(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$arguments.noFlow) {
|
||||||
|
const flowInfo = await getFlowHeaders(url);
|
||||||
if (flowInfo) {
|
if (flowInfo) {
|
||||||
res.set('subscription-userinfo', flowInfo);
|
res.set('subscription-userinfo', flowInfo);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
$.error(
|
$.error(
|
||||||
`组合订阅 ${name} 中的子订阅 ${
|
`组合订阅 ${name} 中的子订阅 ${
|
||||||
|
Loading…
x
Reference in New Issue
Block a user