sofia-cloud / src /app /api /content /route.ts
Gmagl
Add Sofia Cloud complete files
333c51a
Raw
History Blame
2.45 kB
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 }
);
}
}