import { ImageResponse } from 'next/og'; import { NextRequest } from 'next/server'; import { join } from 'path'; import { readFileSync } from 'fs'; export async function GET(req: NextRequest) { try { const { searchParams } = new URL(req.url); // Read metrics const score = searchParams.get('score') || '0 / 0'; const accuracy = searchParams.get('accuracy') || '0%'; const qs = searchParams.get('qs') || '0'; const rank = searchParams.get('rank') || '#--'; // Read user info const name = searchParams.get('name') || 'Student'; const target = searchParams.get('target') || 'JEE'; const plan = searchParams.get('plan') || 'Free'; // Load logo from disk and convert to base64 const logoPath = join(process.cwd(), 'public', 'PragatiVeer_Logo', 'PNG_Logos', 'Rectangular_dark_background.png'); let logoUrl = ''; try { const logoData = readFileSync(logoPath); logoUrl = `data:image/png;base64,${logoData.toString('base64')}`; } catch (e) { console.error('Failed to load logo', e); } return new ImageResponse( (
{/* Subtle grid background overlay */}
{/* Header */}
Performance Report
{/* Main Content - 2x2 Grid */}
Today's Score {score}
Accuracy {accuracy}
Qs Attempted {qs}
City Rank {rank}
{/* Footer */}
{/* Divider */}
{/* User Avatar Placeholder */}
{name.charAt(0).toUpperCase()}
{name}
{`${target} Aspirant`}
•
{`${plan} Plan`}
pragativeer.com
), { width: 1080, height: 1080, } ); } catch (e: any) { return new Response(`Failed to generate image`, { status: 500, }); } }