feat: fallback engine errors
You can now make engines for individual pages, uncovered pages will be handled by readability or other engines
This commit is contained in:
parent
26ed97b4e3
commit
736fa9578b
@ -63,14 +63,12 @@ export class Distributor {
|
|||||||
throw new NotHtmlMimetypeError();
|
throw new NotHtmlMimetypeError();
|
||||||
}
|
}
|
||||||
|
|
||||||
const engine = this.getFallbackEngine(urlObj.hostname, engineName);
|
|
||||||
|
|
||||||
const input = new HandlerInput(
|
const input = new HandlerInput(
|
||||||
await decodeStream(data, parseEncodingName(mime)),
|
await decodeStream(data, parseEncodingName(mime)),
|
||||||
remoteUrl
|
remoteUrl
|
||||||
);
|
);
|
||||||
|
|
||||||
let output = await engine.handle(input);
|
let output = await this.processEngines(urlObj.hostname, input, engineName);
|
||||||
|
|
||||||
// Sanitize output before middlewares, because middlewares can add unsafe tags
|
// Sanitize output before middlewares, because middlewares can add unsafe tags
|
||||||
output = {
|
output = {
|
||||||
@ -108,18 +106,28 @@ export class Distributor {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
getFallbackEngine(host: string, specified?: string): Engine {
|
async processEngines(
|
||||||
|
host: string,
|
||||||
|
input: HandlerInput,
|
||||||
|
specified?: string
|
||||||
|
): Promise<EngineOutput> {
|
||||||
if (specified) {
|
if (specified) {
|
||||||
return this.engines_fallback[this.engines_id[specified]];
|
return await this.engines_fallback[this.engines_id[specified]].handle(
|
||||||
|
input
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const engine of this.engines_fallback) {
|
for (const engine of this.engines_fallback) {
|
||||||
if (micromatch.isMatch(host, engine.domains)) {
|
if (micromatch.isMatch(host, engine.domains)) {
|
||||||
return engine;
|
try {
|
||||||
|
return await engine.handle(input);
|
||||||
|
} catch {
|
||||||
|
/*Try next engine*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.engines_fallback[0];
|
return await this.engines_fallback[0].handle(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
async processMiddlewares(
|
async processMiddlewares(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user