@@ -1715,7 +1715,7 @@ export const getSearchContexts = async (domain: string) => sew(() =>
17151715 } , /* minRequiredRole = */ OrgRole . GUEST ) , /* allowSingleTenantUnauthedAccess = */ true
17161716 ) ) ;
17171717
1718- export const getRepoImage = async ( repoId : number , domain : string ) : Promise < Response | ServiceError > => sew ( async ( ) => {
1718+ export const getRepoImage = async ( repoId : number , domain : string ) : Promise < ArrayBuffer | ServiceError > => sew ( async ( ) => {
17191719 return await withAuth ( async ( userId ) => {
17201720 return await withOrgMembership ( userId , domain , async ( { org } ) => {
17211721 const repo = await prisma . repo . findUnique ( {
@@ -1736,22 +1736,6 @@ export const getRepoImage = async (repoId: number, domain: string): Promise<Resp
17361736 return notFound ( ) ;
17371737 }
17381738
1739- // Only proxy images from self-hosted instances that might require authentication
1740- const imageUrl = new URL ( repo . imageUrl ) ;
1741-
1742- const publicHostnames = [
1743- 'github.com' ,
1744- 'gitlab.com' ,
1745- 'avatars.githubusercontent.com' ,
1746- 'gitea.com' ,
1747- 'bitbucket.org' ,
1748- ] ;
1749- const isPublicInstance = publicHostnames . includes ( imageUrl . hostname ) ;
1750-
1751- if ( isPublicInstance ) {
1752- return Response . redirect ( repo . imageUrl ) ;
1753- }
1754-
17551739 let authHeaders : Record < string , string > = { } ;
17561740 for ( const { connection } of repo . connections ) {
17571741 try {
@@ -1766,7 +1750,7 @@ export const getRepoImage = async (repoId: number, domain: string): Promise<Resp
17661750 const config = connection . config as unknown as GitlabConnectionConfig ;
17671751 if ( config . token ) {
17681752 const token = await getTokenFromConfig ( config . token , connection . orgId , prisma ) ;
1769- authHeaders [ 'Authorization ' ] = `Bearer ${ token } ` ;
1753+ authHeaders [ 'PRIVATE-TOKEN ' ] = token ;
17701754 break ;
17711755 }
17721756 } else if ( connection . connectionType === 'gitea' ) {
@@ -1792,15 +1776,8 @@ export const getRepoImage = async (repoId: number, domain: string): Promise<Resp
17921776 return notFound ( ) ;
17931777 }
17941778
1795- const contentType = response . headers . get ( 'content-type' ) || 'image/png' ;
17961779 const imageBuffer = await response . arrayBuffer ( ) ;
1797-
1798- return new Response ( imageBuffer , {
1799- headers : {
1800- 'Content-Type' : contentType ,
1801- 'Cache-Control' : 'public, max-age=3600' ,
1802- } ,
1803- } ) ;
1780+ return imageBuffer ;
18041781 } catch ( error ) {
18051782 logger . error ( `Error proxying image for repo ${ repoId } :` , error ) ;
18061783 return notFound ( ) ;
0 commit comments