Skip to content

Commit 48bc83c

Browse files
committed
Use a more robust company avatar discovery service
1 parent ba8267e commit 48bc83c

File tree

1 file changed

+10
-31
lines changed

1 file changed

+10
-31
lines changed
Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,21 @@
1-
import { fetchWithTimeout } from "../../misc/fetchWithTimeout";
21
import 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
224
export 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(/^https?:\/\//, "")
16+
.replace(/\/$/, "");
17+
return {
18+
src: `https://favicon.show/${websiteUrlWithoutScheme}`,
19+
title: "Company favicon",
20+
};
4221
}

0 commit comments

Comments
 (0)