MCPcopy Create free account
hub / github.com/sourcebot-dev/sourcebot / getRepoImageSrc

Function getRepoImageSrc

packages/web/src/lib/utils.ts:593–619  ·  view source on GitHub ↗
(imageUrl: string | undefined, repoId: number)

Source from the content-addressed store, hash-verified

591}
592
593export 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
621export const isHttpError = (error: unknown, status: number): boolean => {
622 return error !== null

Callers 3

LandingPageFunction · 0.90
RepoVisitHistoryFunction · 0.90
getColumnsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected