ai-bot/app/api/article/[id]/route.ts

26 lines
832 B
TypeScript
Raw Permalink Normal View History

2025-02-07 19:02:22 +08:00
import { verifySession } from "@/app/_lib/dal";
import { getCollection } from "@/app/_lib/mongodb";
import { ObjectId } from "mongodb";
import { NextRequest } from "next/server";
export async function DELETE(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
try {
const session = await verifySession()
// Check if the user is authenticated
if (!session) {
// User is not authenticated
return new Response(null, { status: 401 })
}
// 获取路径参数
const slug = (await params).id
const collection = await getCollection('article')
collection.deleteOne({
_id: new ObjectId(slug)
})
return Response.json({ message: '删除成功' })
} catch (e) {
return Response.error()
}
}