From af478fd9296d8f43d171138299e8149ba31942a5 Mon Sep 17 00:00:00 2001 From: Sead Feng Date: Tue, 3 Sep 2024 17:15:59 +0800 Subject: [PATCH] add iconResponse.ok --- src/app/favicon/[domain]/route.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/app/favicon/[domain]/route.ts b/src/app/favicon/[domain]/route.ts index 84206ee..577e8c0 100644 --- a/src/app/favicon/[domain]/route.ts +++ b/src/app/favicon/[domain]/route.ts @@ -97,11 +97,27 @@ export async function GET(request: NextRequest, { params: { domain } }: { params }); } const iconResponse = await fetch(selectedIcon.href, { headers }); - const iconBuffer = await iconResponse.arrayBuffer(); - // Calculate execution time const endTime = Date.now(); const executionTime = endTime - startTime; + if (!iconResponse.ok) { + const firstLetter = domain.charAt(0).toUpperCase(); + const svgContent = ` + + + ${firstLetter} + + `; + return new Response(svgContent, { + status: 404, + headers: { + 'Cache-Control': 'public, max-age=86400', + 'Content-Type': 'image/svg+xml', + 'X-Execution-Time': `${executionTime}ms` + } + }); + } + const iconBuffer = await iconResponse.arrayBuffer(); // Return the image response with execution time return new Response(iconBuffer, {