Adapted engines to work with HandlerInput

This commit is contained in:
DarkCat09 2023-09-11 13:07:02 +04:00
parent 456a472031
commit bbbfe480eb
No known key found for this signature in database
GPG Key ID: 0A26CD5B3345D6E3
4 changed files with 12 additions and 12 deletions

View File

@ -1,12 +1,14 @@
import { DOMWindow } from "jsdom";
import { HandlerInput } from "./handler-input";
import { IHandlerOutput } from "./handler.interface";
import { EngineParseError } from "../errors/main";
export default async function google(
window: DOMWindow,
input: HandlerInput,
): Promise<IHandlerOutput> {
const document = input.parseDom().window.document;
const googleAnchors = [
...window.document.querySelectorAll("a[jsname=ACyKwe]"),
...document.querySelectorAll("a[jsname=ACyKwe]"),
] as HTMLAnchorElement[];
if (!googleAnchors) {

View File

@ -2,15 +2,12 @@ import { IHandlerOutput } from "./handler.interface";
import { Engines, EngineFunction, EnginesMatch } from "../types/handlers";
import axios from "../types/axios";
import { JSDOM } from "jsdom";
import micromatch from "micromatch";
import readability from "./readability";
import google, { GoogleDomains } from "./google";
import stackoverflow, { StackOverflowDomains } from "./stackoverflow/main";
import { generateProxyUrl } from "../utils/generate";
import isLocalResource from "../utils/islocal";
import { LocalResourceError, NotHtmlMimetypeError } from "../errors/main";

View File

@ -1,12 +1,12 @@
import { Readability } from "@mozilla/readability";
import { HandlerInput } from "./handler-input";
import { IHandlerOutput } from "./handler.interface";
import { DOMWindow } from "jsdom";
import { EngineParseError } from "../errors/main";
export default async function readability(
window: DOMWindow
input: HandlerInput,
): Promise<IHandlerOutput> {
const reader = new Readability(window.document);
const reader = new Readability(input.parseDom().window.document);
const parsed = reader.parse();
if (!parsed) {

View File

@ -1,13 +1,14 @@
import { HandlerInput } from "../handler-input";
import { IHandlerOutput } from "../handler.interface";
import { DOMWindow } from "jsdom";
import { EngineParseError } from "../../errors/main";
import qPostsHandler from "./questions-posts";
export default async function stackoverflow(
window: DOMWindow,
input: HandlerInput,
): Promise<IHandlerOutput> {
const url = new URL(window.location.href);
const window = input.parseDom().window;
const url = new URL(window.location.href);
const path = url.pathname.split("/").filter((p) => p !== "");
let result: IHandlerOutput = {