Skip to content

Commit aad5ac6

Browse files
fix(og-images): wrap Buffer in Uint8Array for Response body (#568)
Astro uses Web API typings; Response doesn’t accept Node Buffer. Convert the generated OG image Buffer to Uint8Array before constructing Response to satisfy BodyInit and fix the build/type error. Closes #560
1 parent aad228f commit aad5ac6

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/pages/og.png.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { APIRoute } from "astro";
22
import { generateOgImageForSite } from "@/utils/generateOgImages";
33

4-
export const GET: APIRoute = async () =>
5-
new Response(await generateOgImageForSite(), {
4+
export const GET: APIRoute = async () => {
5+
const buffer = await generateOgImageForSite();
6+
return new Response(new Uint8Array(buffer), {
67
headers: { "Content-Type": "image/png" },
78
});
9+
};

src/pages/posts/[...slug]/index.png.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ export const GET: APIRoute = async ({ props }) => {
2727
});
2828
}
2929

30-
return new Response(
31-
await generateOgImageForPost(props as CollectionEntry<"blog">),
32-
{
33-
headers: { "Content-Type": "image/png" },
34-
}
35-
);
30+
const buffer = await generateOgImageForPost(props as CollectionEntry<"blog">);
31+
return new Response(new Uint8Array(buffer), {
32+
headers: { "Content-Type": "image/png" },
33+
});
3634
};

0 commit comments

Comments
 (0)