feat: 订阅列表的流量信息兼容远程和本地合并的情况, 排除设置了不查询订阅信息的链接

This commit is contained in:
xream 2024-03-08 18:40:44 +08:00
parent 23cf81d0a5
commit 7beff4013f
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
3 changed files with 42 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.242",
"version": "2.14.243",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {

View File

@ -722,6 +722,7 @@ function Clash_All() {
'hysteria',
'hysteria2',
'wireguard',
'ssh',
].includes(proxy.type)
) {
throw new Error(

View File

@ -43,7 +43,10 @@ async function getFlowInfo(req, res) {
);
return;
}
if (sub.source === 'local') {
if (
sub.source === 'local' &&
!['localFirst', 'remoteFirst'].includes(sub.mergeSources)
) {
failed(
res,
new RequestInvalidError(
@ -55,7 +58,42 @@ async function getFlowInfo(req, res) {
return;
}
try {
const flowHeaders = 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) {
failed(
res,
new RequestInvalidError(
'NO_FLOW_INFO',
'N/A',
`Subscription ${name}: noFlow`,
),
);
return;
}
const flowHeaders = await getFlowHeaders(url);
if (!flowHeaders) {
failed(
res,