@@ -1715,7 +1715,7 @@ export const getSearchContexts = async (domain: string) => sew(() =>
1715
1715
} , /* minRequiredRole = */ OrgRole . GUEST ) , /* allowSingleTenantUnauthedAccess = */ true
1716
1716
) ) ;
1717
1717
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 ( ) => {
1719
1719
return await withAuth ( async ( userId ) => {
1720
1720
return await withOrgMembership ( userId , domain , async ( { org } ) => {
1721
1721
const repo = await prisma . repo . findUnique ( {
@@ -1736,22 +1736,6 @@ export const getRepoImage = async (repoId: number, domain: string): Promise<Resp
1736
1736
return notFound ( ) ;
1737
1737
}
1738
1738
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
-
1755
1739
let authHeaders : Record < string , string > = { } ;
1756
1740
for ( const { connection } of repo . connections ) {
1757
1741
try {
@@ -1766,7 +1750,7 @@ export const getRepoImage = async (repoId: number, domain: string): Promise<Resp
1766
1750
const config = connection . config as unknown as GitlabConnectionConfig ;
1767
1751
if ( config . token ) {
1768
1752
const token = await getTokenFromConfig ( config . token , connection . orgId , prisma ) ;
1769
- authHeaders [ 'Authorization ' ] = `Bearer ${ token } ` ;
1753
+ authHeaders [ 'PRIVATE-TOKEN ' ] = token ;
1770
1754
break ;
1771
1755
}
1772
1756
} else if ( connection . connectionType === 'gitea' ) {
@@ -1792,15 +1776,8 @@ export const getRepoImage = async (repoId: number, domain: string): Promise<Resp
1792
1776
return notFound ( ) ;
1793
1777
}
1794
1778
1795
- const contentType = response . headers . get ( 'content-type' ) || 'image/png' ;
1796
1779
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 ;
1804
1781
} catch ( error ) {
1805
1782
logger . error ( `Error proxying image for repo ${ repoId } :` , error ) ;
1806
1783
return notFound ( ) ;
0 commit comments