Skip to content

Commit b556af5

Browse files
committed
support old gitlab token case, simplify getImage action, feedback
1 parent 89278fc commit b556af5

File tree

3 files changed

+10
-31
lines changed

3 files changed

+10
-31
lines changed

packages/web/src/actions.ts

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

packages/web/src/app/api/[domain]/repos/[repoId]/image/route.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ export async function GET(
1414
}
1515

1616
const result = await getRepoImage(repoIdNum, domain);
17-
1817
if (isServiceError(result)) {
1918
return new Response(result.message, { status: result.statusCode });
2019
}
2120

22-
return result;
21+
return new Response(result, {
22+
headers: {
23+
'Content-Type': 'image/png',
24+
'Cache-Control': 'public, max-age=3600',
25+
},
26+
});
2327
}

packages/web/src/app/layout.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { getEntitlements } from "@/features/entitlements/server";
1313
export const metadata: Metadata = {
1414
title: "Sourcebot",
1515
description: "Sourcebot",
16+
manifest: "/manifest.json",
1617
};
1718

1819
export default function RootLayout({
@@ -26,9 +27,6 @@ export default function RootLayout({
2627
// @see : https://github.com/pacocoursey/next-themes?tab=readme-ov-file#with-app
2728
suppressHydrationWarning
2829
>
29-
<head>
30-
<link rel="manifest" href="/manifest.json" />
31-
</head>
3230
<body>
3331
<Toaster />
3432
<SessionProvider>

0 commit comments

Comments
 (0)