import { NextRequest, NextResponse } from 'next/server' import fs from 'fs/promises' import path from 'path' export async function GET(req: NextRequest) { try { const { searchParams } = new URL(req.url) const filename = searchParams.get('file') if (!filename) { return NextResponse.json({ error: 'Filename required' }, { status: 400 }) } const screenshotsDir = path.join(process.cwd(), 'screenshots') const filePath = path.join(screenshotsDir, filename) const file = await fs.readFile(filePath) return new NextResponse(file, { headers: { 'Content-Type': 'image/png', 'Content-Disposition': `inline; filename="${filename}"` } }) } catch (e: any) { return NextResponse.json({ error: e.message }, { status: 404 }) } }