(imageUrl: string | undefined, repoId: number)
| 591 | } |
| 592 | |
| 593 | export const getRepoImageSrc = (imageUrl: string | undefined, repoId: number): string | undefined => { |
| 594 | if (!imageUrl) return undefined; |
| 595 | |
| 596 | try { |
| 597 | const url = new URL(imageUrl); |
| 598 | |
| 599 | // List of known public instances that don't require authentication |
| 600 | const publicHostnames = [ |
| 601 | 'github.com', |
| 602 | 'avatars.githubusercontent.com', |
| 603 | 'gitea.com', |
| 604 | 'bitbucket.org', |
| 605 | ]; |
| 606 | |
| 607 | const isPublicInstance = publicHostnames.includes(url.hostname); |
| 608 | |
| 609 | if (isPublicInstance) { |
| 610 | return imageUrl; |
| 611 | } else { |
| 612 | // Use the proxied route for self-hosted instances |
| 613 | return `/api/repos/${repoId}/image`; |
| 614 | } |
| 615 | } catch { |
| 616 | // If URL parsing fails, use the original URL |
| 617 | return imageUrl; |
| 618 | } |
| 619 | }; |
| 620 | |
| 621 | export const isHttpError = (error: unknown, status: number): boolean => { |
| 622 | return error !== null |
no outgoing calls
no test coverage detected