26 lines
832 B
TypeScript
26 lines
832 B
TypeScript
|
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()
|
||
|
}
|
||
|
}
|