File size: 1,324 Bytes
5c0175e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// GET /api/queue — processing queue status.
import { NextResponse } from "next/server";
import { getQueueView } from "@/lib/scan-engine";
import { db } from "@/lib/db";

export const dynamic = "force-dynamic";

export async function GET() {
  const [queue, recentDone, recentError] = await Promise.all([
    getQueueView(),
    db.queueItem.findMany({
      where: { status: "done" },
      orderBy: { finishedAt: "desc" },
      take: 5,
      include: { video: true },
    }),
    db.queueItem.findMany({
      where: { status: "error" },
      orderBy: { finishedAt: "desc" },
      take: 5,
      include: { video: true },
    }),
  ]);

  return NextResponse.json({
    active: queue,
    recentlyDone: recentDone.map((q) => ({
      id: q.id,
      videoId: q.videoId,
      videoName: q.video?.name ?? "Unknown",
      finishedAt: q.finishedAt?.toISOString() ?? null,
    })),
    recentErrors: recentError.map((q) => ({
      id: q.id,
      videoId: q.videoId,
      videoName: q.video?.name ?? "Unknown",
      errorMessage: q.errorMessage,
      finishedAt: q.finishedAt?.toISOString() ?? null,
    })),
    totals: {
      queued: queue.filter((q) => q.status === "queued").length,
      running: queue.filter((q) => q.status === "running").length,
    },
  });
}