echos-ocr/src/app/api/cards/[id]/reprocess/route.ts
Randall Stillwell 9ea9ca741c Allow reprocessing any card, not just errored ones
The Reprocess button and dropdown item were only visible for cards
with ocrStatus "error". Now they appear for any card that isn't
currently processing, so users can re-run OCR on completed cards too
(e.g. after changing AI settings).

Made-with: Cursor
2026-03-12 12:36:22 -05:00

36 lines
991 B
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/db";
import { reprocessCard } from "@/lib/ocr";
export async function POST(
_request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params;
const card = await prisma.responseCard.findUnique({ where: { id } });
if (!card) {
return NextResponse.json({ error: "Card not found" }, { status: 404 });
}
if (card.ocrStatus === "processing") {
return NextResponse.json(
{ error: "Card is already being processed" },
{ status: 400 }
);
}
reprocessCard(id).catch((err) => {
console.error(`[reprocess] Card ${id} reprocessing failed:`, err);
});
return NextResponse.json({ success: true });
} catch (error) {
console.error("[cards/[id]/reprocess POST]", error);
return NextResponse.json(
{ error: "Failed to start reprocessing" },
{ status: 500 }
);
}
}