mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-10 22:09:00 +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();
|
||||
});
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
|
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