Skip to content

Commit 143dd80

Browse files
authored
fix: use base64 decoding for README image proxy to prevent binary corruption (#40)
> https://docs.github.com/en/rest/repos/contents
1 parent bb23d9f commit 143dd80

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

  • apps/web/src/app/api/github-image

apps/web/src/app/api/github-image/route.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,16 @@ export async function GET(request: NextRequest) {
3838
repo,
3939
path,
4040
...(ref ? { ref } : {}),
41-
mediaType: { format: "raw" },
4241
});
4342

43+
if (Array.isArray(data) || !("content" in data) || !data.content) {
44+
return NextResponse.json({ error: "Image not found" }, { status: 404 });
45+
}
46+
47+
const buffer = Buffer.from(data.content, "base64");
4448
const ext = path.split(".").pop()?.toLowerCase() || "";
4549
const contentType = MIME_TYPES[ext] || "application/octet-stream";
4650

47-
const buffer =
48-
typeof data === "string"
49-
? Buffer.from(data, "binary")
50-
: Buffer.from(data as unknown as ArrayBuffer);
51-
5251
return new NextResponse(buffer, {
5352
headers: {
5453
"Content-Type": contentType,

0 commit comments

Comments
 (0)