import { NextRequest, NextResponse } from "next/server"; import { query } from "../../../../../db"; export const dynamic = "force-dynamic"; export async function GET( req: NextRequest, { params }: { params: Promise<{ id: string }> | { id: string } } ) { try { // Handle both Promise and synchronous params for Next.js version compatibility const resolvedParams = await params; const { id } = resolvedParams; const docId = parseInt(id, 10); if (isNaN(docId)) { return NextResponse.json({ error: "Invalid document ID" }, { status: 400 }); } const res = await query( "SELECT filename, processing_logs FROM documents WHERE id = $1", [docId] ); if (res.rowCount === 0 || !res.rows[0]) { return NextResponse.json({ error: "Document not found" }, { status: 404 }); } return NextResponse.json({ filename: res.rows[0].filename, processing_logs: res.rows[0].processing_logs || null }); } catch (error: any) { console.error("Error fetching document logs:", error); return NextResponse.json({ error: error.message }, { status: 500 }); } }