feat: engine choose
This commit is contained in:
parent
219e3ee716
commit
5325941078
@ -1,7 +1,14 @@
|
||||
import { IHandlerOutput } from "./handler.interface";
|
||||
import { readability } from "./readability";
|
||||
|
||||
export default function handlePage(url: string): Promise<IHandlerOutput> {
|
||||
export default function handlePage(
|
||||
url: string,
|
||||
engine?: string
|
||||
): Promise<IHandlerOutput> {
|
||||
if (engine) {
|
||||
return engines[engine](url);
|
||||
}
|
||||
|
||||
const host = new URL(url).hostname;
|
||||
return fallback[host]?.(url) || fallback["*"](url);
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
import NodeCache from "node-cache";
|
||||
import { EngineRequest } from "../types/requests";
|
||||
import { FastifyInstance } from "fastify";
|
||||
import { engines } from "../handlers/main";
|
||||
import handlePage from "../handlers/main";
|
||||
|
||||
export default function parseRoute(cache: NodeCache) {
|
||||
return async (fastify: FastifyInstance) => {
|
||||
fastify.get("/parse", async (req: EngineRequest) => {
|
||||
const url = req.query.url;
|
||||
const engine = req.query.engine || "readability";
|
||||
const parsed = await engines[engine](url);
|
||||
const parsed = await handlePage(req.query.url, req.query.engine);
|
||||
|
||||
cache.set(req.originalUrl || req.url, {
|
||||
content: parsed,
|
||||
|
Loading…
x
Reference in New Issue
Block a user