File tree Expand file tree Collapse file tree 1 file changed +10
-31
lines changed
src/atomic-crm/providers/commons Expand file tree Collapse file tree 1 file changed +10
-31
lines changed Original file line number Diff line number Diff line change 1- import { fetchWithTimeout } from "../../misc/fetchWithTimeout" ;
21import type { Company } from "../../types" ;
32
4- // Helper function to get the favicon URL
5- async function getFaviconUrl ( website : string ) : Promise < string | null > {
6- try {
7- // get favicon from domain
8- const url = new URL ( website ) ;
9- const domain = url . origin ;
10- const faviconUrl = `${ domain } /favicon.ico` ;
11- const response = await fetchWithTimeout ( faviconUrl ) ;
12- if ( response . ok ) {
13- return faviconUrl ;
14- }
15- } catch {
16- return null ;
17- }
18- return null ;
19- }
20-
213// Main function to get the avatar URL
224export async function getCompanyAvatar ( record : Partial < Company > ) : Promise < {
235 src : string ;
246 title : string ;
257} | null > {
8+ // TODO: Step 1: Try to get image from LinkedIn.
9+
10+ // Step 2: Fallback to the favicon from website domain
2611 if ( ! record . website ) {
2712 return null ;
2813 }
29-
30- // Step 1: Try to get favicon from website domain
31- const faviconUrl = await getFaviconUrl ( record . website ) ;
32- if ( faviconUrl ) {
33- return {
34- src : faviconUrl ,
35- title : "Company favicon" ,
36- } ;
37- }
38-
39- // TODO: Step 2: Try to get image from LinkedIn.
40-
41- return null ;
14+ const websiteUrlWithoutScheme = record . website
15+ . replace ( / ^ h t t p s ? : \/ \/ / , "" )
16+ . replace ( / \/ $ / , "" ) ;
17+ return {
18+ src : `https://favicon.show/${ websiteUrlWithoutScheme } ` ,
19+ title : "Company favicon" ,
20+ } ;
4221}
You can’t perform that action at this time.
0 commit comments