Spaces:
Build error
Build error
File size: 2,449 Bytes
333c51a | 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | import { NextRequest, NextResponse } from "next/server";
import { db } from "@/lib/db";
// GET - Listar todo el contenido
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const type = searchParams.get("type");
const platform = searchParams.get("platform");
const status = searchParams.get("status");
const limit = parseInt(searchParams.get("limit") || "50");
const where: Record<string, unknown> = {};
if (type) where.type = type;
if (platform) where.platform = platform;
if (status) where.status = status;
const contents = await db.content.findMany({
where,
include: {
character: true,
censorFlags: true,
},
orderBy: { createdAt: "desc" },
take: limit,
});
// Estadísticas
const stats = {
total: await db.content.count(),
images: await db.content.count({ where: { type: "image" } }),
videos: await db.content.count({ where: { type: "video" } }),
pending: await db.content.count({ where: { status: "pending" } }),
processing: await db.content.count({ where: { status: "processing" } }),
completed: await db.content.count({ where: { status: "completed" } }),
failed: await db.content.count({ where: { status: "failed" } }),
};
return NextResponse.json({
success: true,
contents,
stats
});
} catch (error) {
console.error("Error fetching content:", error);
return NextResponse.json(
{ success: false, error: "Error al obtener contenido" },
{ status: 500 }
);
}
}
// DELETE - Eliminar contenido
export async function DELETE(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const id = searchParams.get("id");
if (!id) {
return NextResponse.json(
{ success: false, error: "ID requerido" },
{ status: 400 }
);
}
// Eliminar flags de censura asociados
await db.censorFlag.deleteMany({
where: { contentId: id }
});
// Eliminar contenido
await db.content.delete({
where: { id }
});
return NextResponse.json({
success: true,
message: "Contenido eliminado"
});
} catch (error) {
console.error("Error deleting content:", error);
return NextResponse.json(
{ success: false, error: "Error al eliminar contenido" },
{ status: 500 }
);
}
}
|