do not pass browser instance to content-handler
This commit is contained in:
@ -36,7 +36,6 @@
|
|||||||
"linkedom": "^0.14.16",
|
"linkedom": "^0.14.16",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"luxon": "^3.0.4",
|
"luxon": "^3.0.4",
|
||||||
"puppeteer-core": "^20.9.0",
|
|
||||||
"underscore": "^1.13.6",
|
"underscore": "^1.13.6",
|
||||||
"uuid": "^9.0.0"
|
"uuid": "^9.0.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import addressparser from 'addressparser'
|
import addressparser from 'addressparser'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { parseHTML } from 'linkedom'
|
import { parseHTML } from 'linkedom'
|
||||||
import { Browser } from 'puppeteer-core'
|
|
||||||
import { v4 as uuid } from 'uuid'
|
import { v4 as uuid } from 'uuid'
|
||||||
|
|
||||||
interface Unsubscribe {
|
interface Unsubscribe {
|
||||||
@ -61,7 +60,7 @@ export abstract class ContentHandler {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
async preHandle(url: string, browser?: Browser): Promise<PreHandleResult> {
|
async preHandle(url: string): Promise<PreHandleResult> {
|
||||||
return Promise.resolve({ url })
|
return Promise.resolve({ url })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import { parseHTML } from 'linkedom'
|
import { parseHTML } from 'linkedom'
|
||||||
import { Browser } from 'puppeteer-core'
|
|
||||||
import {
|
import {
|
||||||
ContentHandler,
|
ContentHandler,
|
||||||
NewsletterInput,
|
NewsletterInput,
|
||||||
@ -104,8 +103,7 @@ const newsletterHandlers: ContentHandler[] = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
export const preHandleContent = async (
|
export const preHandleContent = async (
|
||||||
url: string,
|
url: string
|
||||||
browser: Browser
|
|
||||||
): Promise<PreHandleResult | undefined> => {
|
): Promise<PreHandleResult | undefined> => {
|
||||||
// Before we run the regular handlers we check to see if we need tp
|
// Before we run the regular handlers we check to see if we need tp
|
||||||
// pre-resolve the URL. TODO: This should probably happen recursively,
|
// pre-resolve the URL. TODO: This should probably happen recursively,
|
||||||
@ -129,7 +127,7 @@ export const preHandleContent = async (
|
|||||||
for (const handler of contentHandlers) {
|
for (const handler of contentHandlers) {
|
||||||
if (handler.shouldPreHandle(url)) {
|
if (handler.shouldPreHandle(url)) {
|
||||||
console.log('preHandleContent', handler.name, url)
|
console.log('preHandleContent', handler.name, url)
|
||||||
return handler.preHandle(url, browser)
|
return handler.preHandle(url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return undefined
|
return undefined
|
||||||
|
|||||||
@ -163,8 +163,7 @@ export const fetchContent = async (
|
|||||||
|
|
||||||
// pre handle url with custom handlers
|
// pre handle url with custom handlers
|
||||||
try {
|
try {
|
||||||
const browser = await getBrowserPromise
|
const result = await preHandleContent(url)
|
||||||
const result = await preHandleContent(url, browser)
|
|
||||||
if (result && result.url) {
|
if (result && result.url) {
|
||||||
validateUrlString(url)
|
validateUrlString(url)
|
||||||
url = result.url
|
url = result.url
|
||||||
|
|||||||
Reference in New Issue
Block a user