import fs from 'node:fs';
import { prisma } from '@/lib/db';
import { currentUser } from '@/lib/auth';
import { localPath } from '@/lib/storage';
export const dynamic = 'force-dynamic';
/** Üretim sürerken worker'ın yazdığı son kare. */
export async function GET(_: Request, { params }: { params: Promise<{ id: string }> }) {
  const u = await currentUser(); if (!u) return new Response(null, { status: 401 });
  const { id } = await params;
  const o = await prisma.order.findUnique({ where: { id }, select: { userId: true } });
  if (!o || (o.userId !== u.id && u.role !== 'ADMIN')) return new Response(null, { status: 404 });
  const p = localPath(`orders/${id}/live.jpg`);
  if (!fs.existsSync(p)) return new Response(null, { status: 204 });
  return new Response(fs.readFileSync(p), { headers: { 'Content-Type': 'image/jpeg', 'Cache-Control': 'no-store' } });
}
