Fetch subscription's favicon if the site icon is base64 encoded image

This commit is contained in:
Hongbo Wu 2022-10-18 12:03:23 +08:00
parent 990759da73
commit 22e92256eb
2 changed files with 7 additions and 2 deletions

View file

@ -14,6 +14,7 @@ import { saveSubscription } from './subscriptions'
import { NewsletterEmail } from '../entity/newsletter_email'
import { fetchFavicon } from '../utils/parser'
import { updatePage } from '../elastic/pages'
import { isBase64Image } from '../utils/helpers'
interface NewsletterMessage {
email: string
@ -69,8 +70,8 @@ export const saveNewsletterEmail = async (
return false
}
if (!page.siteIcon) {
// fetch favicon if not already set
if (!page.siteIcon || isBase64Image(page.siteIcon)) {
// fetch favicon if not already set or is a base64 image
const favicon = await fetchFavicon(page.url)
if (favicon) {
page.siteIcon = favicon

View file

@ -269,3 +269,7 @@ export const wordsCount = (text: string, isHtml = true): number => {
return 0
}
}
export const isBase64Image = (str: string): boolean => {
return str.startsWith('data:image/')
}