mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-11 00:29:03 +08:00
Fixed Loon & Surge Bug
This commit is contained in:
parent
da71611d70
commit
1ae804ce6b
@ -117,7 +117,7 @@ if (ENV().isQX) {
|
|||||||
res.status(200).end();
|
res.status(200).end();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
;
|
|
||||||
|
|
||||||
$app.all("/", async (req, res) => {
|
$app.all("/", async (req, res) => {
|
||||||
res.send("Hello from sub-store, made with ❤️ by Peng-YM");
|
res.send("Hello from sub-store, made with ❤️ by Peng-YM");
|
||||||
@ -661,43 +661,54 @@ function ProxyParser(targetPlatform) {
|
|||||||
args.forEach((a) => producers.push(a()));
|
args.forEach((a) => producers.push(a()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function safeMatch(p, line) {
|
||||||
|
let patternMatched;
|
||||||
|
try {
|
||||||
|
patternMatched = p.patternTest(line);
|
||||||
|
} catch (err) {
|
||||||
|
patternMatched = false;
|
||||||
|
}
|
||||||
|
return patternMatched;
|
||||||
|
}
|
||||||
|
|
||||||
function parse(raw) {
|
function parse(raw) {
|
||||||
raw = preprocessing(raw);
|
raw = preprocessing(raw);
|
||||||
const lines = raw.split("\n");
|
const lines = raw.split("\n");
|
||||||
const result = [];
|
const result = [];
|
||||||
|
let lastParser;
|
||||||
|
|
||||||
// convert to json format
|
// convert to json format
|
||||||
for (let line of lines) {
|
for (let line of lines) {
|
||||||
|
// console.log(`Parsing line: ${line}...`);
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
if (line.length === 0) continue; // skip empty line
|
if (line.length === 0) continue; // skip empty line
|
||||||
if (line.startsWith("#")) continue; // skip comments
|
if (line.startsWith("#")) continue; // skip comments
|
||||||
let matched = false;
|
let matched = lastParser && safeMatch(lastParser, line);
|
||||||
|
if (!matched) {
|
||||||
for (const p of parsers) {
|
for (const p of parsers) {
|
||||||
const {patternTest, func} = p;
|
if (safeMatch(p, line)) {
|
||||||
|
lastParser = p;
|
||||||
// some lines with weird format may produce errors!
|
|
||||||
let patternMatched;
|
|
||||||
try {
|
|
||||||
patternMatched = patternTest(line);
|
|
||||||
} catch (err) {
|
|
||||||
patternMatched = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (patternMatched) {
|
|
||||||
matched = true;
|
matched = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!matched) {
|
||||||
|
console.log(`ERROR: Failed to find a rule to parse line: \n${line}\n`);
|
||||||
|
} else {
|
||||||
|
const {func} = lastParser;
|
||||||
// run parser safely.
|
// run parser safely.
|
||||||
try {
|
try {
|
||||||
const proxy = func(line);
|
const proxy = func(line);
|
||||||
if (!proxy) {
|
if (!proxy) {
|
||||||
// failed to parse this line
|
// failed to parse this line
|
||||||
console.log(`ERROR: parser return nothing for \n${line}\n`);
|
console.log(`ERROR: parser return nothing for \n${line}\n`);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
// skip unsupported proxies
|
// skip unsupported proxies
|
||||||
// if proxy.supported is undefined, assume that all platforms are supported.
|
// if proxy.supported is undefined, assume that all platforms are supported.
|
||||||
if (proxy.supported && proxy.supported[targetPlatform] === false)
|
if (proxy.supported && proxy.supported[targetPlatform] === false)
|
||||||
continue;
|
continue;
|
||||||
result.push(proxy);
|
result.push(proxy);
|
||||||
break;
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(
|
console.log(
|
||||||
`ERROR: Failed to parse line: \n ${line}\n Reason: ${err}`
|
`ERROR: Failed to parse line: \n ${line}\n Reason: ${err}`
|
||||||
@ -705,10 +716,6 @@ function ProxyParser(targetPlatform) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!matched) {
|
|
||||||
console.log(`ERROR: Failed to find a rule to parse line: \n${line}\n`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
backend/sub-store.min.js
vendored
2
backend/sub-store.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user