Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions nextstep-backend/src/services/company_logo_service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import axios from 'axios';

export const getCompanyLogo = async (companyName: string): Promise<string | null> => {
export const getCompanyLogo = async (companyName: string, extensions: string[] = ['.com', '.co.il']): Promise<string | null> => {
try {
const response = await axios.get(`https://logo.clearbit.com/${encodeURIComponent(companyName)}.com`);
return response.status === 200 ? response.config.url ?? null : null;
for (const extension of extensions) {
try {
const response = await axios.get(`https://logo.clearbit.com/${encodeURIComponent(companyName)}${extension}`);
if (response.status === 200) {
return response.config.url!;
}
} catch (error) {
// Continue to next extension if this one fails
continue;
}
}
return null;
} catch (error) {
if (error instanceof Error) {
console.error(`Failed to fetch logo for company: ${companyName}`, error.message);
Expand Down
Loading