Skip to content

Commit e42fe26

Browse files
committed
fixes
1 parent df6316d commit e42fe26

File tree

9 files changed

+154
-473
lines changed

9 files changed

+154
-473
lines changed

examples/image/app/api/generate/route.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { streamText } from "ai";
2-
import { gateway } from "@ai-sdk/gateway";
32
import { buildUserPrompt, type Spec } from "@json-render/core";
43
import { imageCatalog } from "@/lib/catalog";
54

@@ -25,7 +24,7 @@ export async function POST(req: Request) {
2524
});
2625

2726
const result = streamText({
28-
model: gateway(process.env.AI_GATEWAY_MODEL ?? DEFAULT_MODEL),
27+
model: process.env.AI_GATEWAY_MODEL ?? DEFAULT_MODEL,
2928
system: SYSTEM_PROMPT,
3029
prompt: userPrompt,
3130
temperature: 0.7,

examples/image/app/api/image/route.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import { renderToSvg, renderToPng } from "@json-render/image/render";
1+
import { renderToPng } from "@json-render/image/render";
22
import { examples } from "@/lib/examples";
33
import type { Spec } from "@json-render/core";
44
import { readFile } from "node:fs/promises";
5-
import { join } from "node:path";
5+
import { createRequire } from "node:module";
6+
7+
const require = createRequire(import.meta.url);
68

79
let fontCache: ArrayBuffer | null = null;
810

911
async function loadFont(): Promise<ArrayBuffer> {
1012
if (fontCache) return fontCache;
11-
const buffer = await readFile(
12-
join(process.cwd(), "public", "Inter-Regular.ttf"),
13-
);
13+
const fontPath =
14+
require.resolve("geist/dist/fonts/geist-sans/Geist-Regular.ttf");
15+
const buffer = await readFile(fontPath);
1416
fontCache = buffer.buffer.slice(
1517
buffer.byteOffset,
1618
buffer.byteOffset + buffer.byteLength,
@@ -49,7 +51,7 @@ async function imageResponse(spec: Spec, name: string, download: boolean) {
4951
const fontData = await loadFont();
5052
const fonts = [
5153
{
52-
name: "Inter",
54+
name: "Geist Sans",
5355
data: fontData,
5456
weight: 400 as const,
5557
style: "normal" as const,
@@ -62,7 +64,7 @@ async function imageResponse(spec: Spec, name: string, download: boolean) {
6264
? `attachment; filename="${name}.png"`
6365
: `inline; filename="${name}.png"`;
6466

65-
return new Response(png as unknown as ArrayBuffer, {
67+
return new Response(Buffer.from(png), {
6668
headers: {
6769
"Content-Type": "image/png",
6870
"Content-Disposition": disposition,

examples/image/app/layout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { Metadata } from "next";
2-
import { Inter } from "next/font/google";
2+
import { Geist } from "next/font/google";
33
import "./globals.css";
44

5-
const inter = Inter({ subsets: ["latin"] });
5+
const geist = Geist({ subsets: ["latin"] });
66

77
export const metadata: Metadata = {
88
title: "json-render Image Example",
@@ -16,7 +16,7 @@ export default function RootLayout({
1616
}) {
1717
return (
1818
<html lang="en">
19-
<body className={inter.className}>{children}</body>
19+
<body className={geist.className}>{children}</body>
2020
</html>
2121
);
2222
}

0 commit comments

Comments
 (0)