mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Remove dom param in preHandler method
This commit is contained in:
parent
f607215826
commit
c9400ca517
9 changed files with 18 additions and 18 deletions
|
|
@ -8,12 +8,12 @@ export class AppleNewsHandler extends ContentHandler {
|
|||
this.name = 'Apple News'
|
||||
}
|
||||
|
||||
shouldPreHandle(url: string, dom?: Document): boolean {
|
||||
shouldPreHandle(url: string): boolean {
|
||||
const u = new URL(url)
|
||||
return u.hostname === 'apple.news'
|
||||
}
|
||||
|
||||
async preHandle(url: string, document?: Document): Promise<PreHandleResult> {
|
||||
async preHandle(url: string): Promise<PreHandleResult> {
|
||||
const MOBILE_USER_AGENT =
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36'
|
||||
const response = await axios.get(url, {
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@ export class BloombergHandler extends ContentHandler {
|
|||
this.name = 'Bloomberg'
|
||||
}
|
||||
|
||||
shouldPreHandle(url: string, dom?: Document): boolean {
|
||||
shouldPreHandle(url: string): boolean {
|
||||
const BLOOMBERG_URL_MATCH =
|
||||
/https?:\/\/(www\.)?bloomberg.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)/
|
||||
return BLOOMBERG_URL_MATCH.test(url.toString())
|
||||
}
|
||||
|
||||
async preHandle(url: string, document?: Document): Promise<PreHandleResult> {
|
||||
async preHandle(url: string): Promise<PreHandleResult> {
|
||||
console.log('prehandling bloomberg url', url)
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ export class DerstandardHandler extends ContentHandler {
|
|||
this.name = 'Derstandard'
|
||||
}
|
||||
|
||||
shouldPreHandle(url: string, dom?: Document): boolean {
|
||||
shouldPreHandle(url: string): boolean {
|
||||
const u = new URL(url)
|
||||
return u.hostname === 'www.derstandard.at'
|
||||
}
|
||||
|
||||
async preHandle(url: string, document?: Document): Promise<PreHandleResult> {
|
||||
async preHandle(url: string): Promise<PreHandleResult> {
|
||||
const response = await axios.get(url, {
|
||||
// set cookie to give consent to get the article
|
||||
headers: {
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ export class ImageHandler extends ContentHandler {
|
|||
this.name = 'Image'
|
||||
}
|
||||
|
||||
shouldPreHandle(url: string, dom?: Document): boolean {
|
||||
shouldPreHandle(url: string): boolean {
|
||||
const IMAGE_URL_PATTERN = /(https?:\/\/.*\.(?:jpg|jpeg|png|webp))/i
|
||||
return IMAGE_URL_PATTERN.test(url.toString())
|
||||
}
|
||||
|
||||
async preHandle(url: string, document?: Document): Promise<PreHandleResult> {
|
||||
async preHandle(url: string): Promise<PreHandleResult> {
|
||||
const title = url.toString().split('/').pop() || 'Image'
|
||||
const content = `
|
||||
<html>
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ export class MediumHandler extends ContentHandler {
|
|||
this.name = 'Medium'
|
||||
}
|
||||
|
||||
shouldPreHandle(url: string, dom?: Document): boolean {
|
||||
shouldPreHandle(url: string): boolean {
|
||||
const u = new URL(url)
|
||||
return u.hostname.endsWith('medium.com')
|
||||
}
|
||||
|
||||
async preHandle(url: string, document?: Document): Promise<PreHandleResult> {
|
||||
async preHandle(url: string): Promise<PreHandleResult> {
|
||||
console.log('prehandling medium url', url)
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ export class PdfHandler extends ContentHandler {
|
|||
this.name = 'PDF'
|
||||
}
|
||||
|
||||
shouldPreHandle(url: string, dom?: Document): boolean {
|
||||
shouldPreHandle(url: string): boolean {
|
||||
const u = new URL(url)
|
||||
const path = u.pathname.replace(u.search, '')
|
||||
return path.endsWith('.pdf')
|
||||
}
|
||||
|
||||
async preHandle(_url: string, document?: Document): Promise<PreHandleResult> {
|
||||
async preHandle(url: string): Promise<PreHandleResult> {
|
||||
return Promise.resolve({ contentType: 'application/pdf' })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,14 +8,14 @@ export class ScrapingBeeHandler extends ContentHandler {
|
|||
this.name = 'ScrapingBee'
|
||||
}
|
||||
|
||||
shouldPreHandle(url: string, dom?: Document): boolean {
|
||||
shouldPreHandle(url: string): boolean {
|
||||
const u = new URL(url)
|
||||
const hostnames = ['nytimes.com', 'news.google.com']
|
||||
|
||||
return hostnames.some((h) => u.hostname.endsWith(h))
|
||||
}
|
||||
|
||||
async preHandle(url: string, document?: Document): Promise<PreHandleResult> {
|
||||
async preHandle(url: string): Promise<PreHandleResult> {
|
||||
console.log('prehandling url with scrapingbee', url)
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -140,11 +140,11 @@ export class TwitterHandler extends ContentHandler {
|
|||
this.name = 'Twitter'
|
||||
}
|
||||
|
||||
shouldPreHandle(url: string, dom?: Document): boolean {
|
||||
shouldPreHandle(url: string): boolean {
|
||||
return !!TWITTER_BEARER_TOKEN && TWITTER_URL_MATCH.test(url.toString())
|
||||
}
|
||||
|
||||
async preHandle(url: string, document?: Document): Promise<PreHandleResult> {
|
||||
async preHandle(url: string): Promise<PreHandleResult> {
|
||||
const tweetId = tweetIdFromStatusUrl(url)
|
||||
if (!tweetId) {
|
||||
throw new Error('could not find tweet id in url')
|
||||
|
|
|
|||
|
|
@ -24,11 +24,11 @@ export class YoutubeHandler extends ContentHandler {
|
|||
this.name = 'Youtube'
|
||||
}
|
||||
|
||||
shouldPreHandle(url: string, dom?: Document): boolean {
|
||||
shouldPreHandle(url: string): boolean {
|
||||
return YOUTUBE_URL_MATCH.test(url.toString())
|
||||
}
|
||||
|
||||
async preHandle(url: string, document?: Document): Promise<PreHandleResult> {
|
||||
async preHandle(url: string): Promise<PreHandleResult> {
|
||||
const videoId = getYoutubeVideoId(url)
|
||||
if (!videoId) {
|
||||
return {}
|
||||
|
|
|
|||
Loading…
Reference in a new issue