Fixed Loon & Surge Bug

This commit is contained in:
Peng-YM 2020-10-27 20:09:48 +08:00
parent da71611d70
commit 1ae804ce6b
2 changed files with 105 additions and 98 deletions

View File

@ -117,7 +117,7 @@ if (ENV().isQX) {
res.status(200).end();
});
}
;
$app.all("/", async (req, res) => {
res.send("Hello from sub-store, made with ❤️ by Peng-YM");
@ -661,43 +661,54 @@ function ProxyParser(targetPlatform) {
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) {
raw = preprocessing(raw);
const lines = raw.split("\n");
const result = [];
let lastParser;
// convert to json format
for (let line of lines) {
// console.log(`Parsing line: ${line}...`);
line = line.trim();
if (line.length === 0) continue; // skip empty line
if (line.startsWith("#")) continue; // skip comments
let matched = false;
let matched = lastParser && safeMatch(lastParser, line);
if (!matched) {
for (const p of parsers) {
const {patternTest, func} = p;
// some lines with weird format may produce errors!
let patternMatched;
try {
patternMatched = patternTest(line);
} catch (err) {
patternMatched = false;
}
if (patternMatched) {
if (safeMatch(p, line)) {
lastParser = p;
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.
try {
const proxy = func(line);
if (!proxy) {
// failed to parse this line
console.log(`ERROR: parser return nothing for \n${line}\n`);
break;
}
// skip unsupported proxies
// if proxy.supported is undefined, assume that all platforms are supported.
if (proxy.supported && proxy.supported[targetPlatform] === false)
continue;
result.push(proxy);
break;
} catch (err) {
console.log(
`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;
}

File diff suppressed because one or more lines are too long