Spaces:
Build error
Build error
File size: 1,471 Bytes
333c51a acbcb20 333c51a acbcb20 333c51a acbcb20 333c51a acbcb20 333c51a acbcb20 333c51a acbcb20 | 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 | import { NextRequest, NextResponse } from "next/server";
import { db } from "@/lib/db";
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const type = searchParams.get("type");
const platform = searchParams.get("platform");
const limit = parseInt(searchParams.get("limit") || "50");
const where: Record<string, unknown> = {};
if (type) where.type = type;
if (platform) where.platform = platform;
const contents = await db.content.findMany({ where, orderBy: { createdAt: "desc" }, take: limit });
const stats = {
total: await db.content.count(),
images: await db.content.count({ where: { type: "image" } }),
videos: await db.content.count({ where: { type: "video" } })
};
return NextResponse.json({ success: true, contents, stats });
} catch {
return NextResponse.json({ success: false, error: "Error" }, { status: 500 });
}
}
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 });
await db.censorFlag.deleteMany({ where: { contentId: id } });
await db.content.delete({ where: { id } });
return NextResponse.json({ success: true });
} catch {
return NextResponse.json({ success: false, error: "Error" }, { status: 500 });
}
} |