58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { auth } from "@/auth";
|
|
import { db } from "@/lib/db";
|
|
|
|
export async function GET(req: Request) {
|
|
// Accept either a logged-in session or the shared display API key
|
|
const displayKey = process.env.API_SECRET_KEY;
|
|
const providedKey = req.headers.get("x-display-key");
|
|
const isDisplayDevice = displayKey && providedKey === displayKey;
|
|
|
|
if (!isDisplayDevice) {
|
|
const session = await auth();
|
|
if (!session?.user) {
|
|
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
|
}
|
|
}
|
|
|
|
const [
|
|
approved,
|
|
review,
|
|
changes,
|
|
todo,
|
|
artists,
|
|
shots,
|
|
renderQueue,
|
|
] = await Promise.all([
|
|
db.shot.count({
|
|
where: { shotApprovalStatus: "CLIENT_APPROVED" },
|
|
}),
|
|
db.shot.count({
|
|
where: { status: { in: ["INTERNAL_REVIEW", "READY_FOR_CLIENT", "CLIENT_REVIEW"] } },
|
|
}),
|
|
db.shot.count({
|
|
where: { status: "REVISIONS" },
|
|
}),
|
|
db.shot.count({
|
|
where: { status: "WAITING" },
|
|
}),
|
|
db.user.count({
|
|
where: { role: "ARTIST", isActive: true },
|
|
}),
|
|
db.shot.count({}),
|
|
db.task.count({
|
|
where: { type: "RENDER", status: { not: "DONE" } },
|
|
}),
|
|
]);
|
|
|
|
return NextResponse.json({
|
|
approved,
|
|
review,
|
|
changes,
|
|
todo,
|
|
artists,
|
|
shots,
|
|
renderQueue,
|
|
});
|
|
}
|