Files
zhuiguang-ai/src/app/api/admin/check-tools/[id]/route.ts
T

36 lines
1.0 KiB
TypeScript

import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { requireAdmin } from "@/lib/admin-auth";
export async function DELETE(
request: Request,
{ params }: { params: { id: string } }
) {
const authError = await requireAdmin();
if (authError) return authError;
try {
const id = parseInt(params.id);
const body = await request.json();
const { type } = body as { type: "published" | "pending" };
if (!type || !["published", "pending"].includes(type)) {
return NextResponse.json(
{ error: "type 参数无效,必须为 published 或 pending" },
{ status: 400 }
);
}
if (type === "published") {
await prisma.tool.delete({ where: { id } });
} else {
await prisma.pendingTool.delete({ where: { id } });
}
return NextResponse.json({ success: true });
} catch (error: unknown) {
const err = error as { message?: string };
return NextResponse.json({ error: err.message }, { status: 500 });
}
}