import { NextRequest, NextResponse } from 'next/server'; import { prisma } from '@/lib/prisma'; import { runOcrOnAttachment } from '@/lib/ocr'; export async function GET( _req: NextRequest, context: { params: Promise<{ id: string }> } ) { try { const { id } = await context.params; const attachment = await prisma.attachment.findUnique({ where: { id }, select: { id: true, filename: true, mimeType: true, extractedText: true }, }); if (!attachment) { return NextResponse.json({ error: 'Attachment not found' }, { status: 404 }); } return NextResponse.json({ id: attachment.id, filename: attachment.filename, extractedText: attachment.extractedText, }); } catch (err: unknown) { return NextResponse.json( { error: err instanceof Error ? err.message : 'Failed to fetch OCR text' }, { status: 500 } ); } } export async function POST( _req: NextRequest, context: { params: Promise<{ id: string }> } ) { try { const { id } = await context.params; const result = await runOcrOnAttachment(id); return NextResponse.json(result); } catch (err: unknown) { return NextResponse.json( { error: err instanceof Error ? err.message : 'OCR execution failed' }, { status: 500 } ); } }