41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { getCollection, getDb } from "@/app/_lib/mongodb";
|
|
import { ObjectId } from "mongodb";
|
|
import { NextRequest } from "next/server";
|
|
|
|
import { verifySession } from "@/app/_lib/dal";
|
|
import { getLinkList, Link } from "@/app/_lib/data/link";
|
|
|
|
export async function GET(req: NextRequest) {
|
|
try {
|
|
const page = parseInt(req.nextUrl.searchParams.get('page') || '1') || 1;
|
|
const pageSize = parseInt(req.nextUrl.searchParams.get('pageSize') || '10') || 10;
|
|
const typeId = req.nextUrl.searchParams.get('typeId') || ''
|
|
|
|
const res = await getLinkList({ page, pageSize, typeId })
|
|
return Response.json(res)
|
|
} catch (e) {
|
|
return Response.error()
|
|
}
|
|
}
|
|
|
|
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('search')
|
|
collection.deleteOne({
|
|
_id: new ObjectId(slug)
|
|
})
|
|
return Response.json({ message: '删除成功' })
|
|
} catch (e) {
|
|
return Response.error()
|
|
}
|
|
}
|