fix: Full config preprocessor bug

This commit is contained in:
Peng-YM
2022-07-07 23:23:58 +08:00
parent 07cae95ff4
commit 2ee515dc23
6 changed files with 41 additions and 16 deletions

View File

@@ -95,10 +95,21 @@ function FullConfig() {
return /^(\[server_local\]|\[Proxy\])/gm.test(raw);
};
const parse = function (raw) {
const regex = /^(\[server_local\]|\[Proxy\])\n?((.|\n)*?)\[/gm;
const result = regex.exec(raw);
if (result) {
return result[2] || '';
const regex = /^\[server_local]|\[Proxy]/gm;
const match = regex.exec(raw);
const results = [];
let first = true;
if (match) {
raw = raw.substring(match.index);
for (const line of raw.split('\n')) {
if (!first && !line.test(/^\s*\[/)) {
results.push(line);
}
// skip the first line
first = false;
}
return results.join('\n');
}
};
return { name, test, parse };

View File

@@ -41,13 +41,27 @@ async function getFlowInfo(req, res) {
return;
}
if (sub.source === 'local') {
failed(res, new RequestInvalidError('NO_FLOW_INFO', 'N/A'));
failed(
res,
new RequestInvalidError(
'NO_FLOW_INFO',
'N/A',
`Local subscription ${name} has no flow information!`,
),
);
return;
}
try {
const flowHeaders = await getFlowHeaders(sub.url);
if (!flowHeaders) {
failed(res, new InternalServerError('NO_FLOW_INFO', 'N/A'));
failed(
res,
new InternalServerError(
'NO_FLOW_INFO',
'No flow info',
`Failed to fetch flow headers`,
),
);
return;
}