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

41 lines
1.3 KiB
TypeScript
Raw Normal View History

2025-02-17 18:17:12 +08:00
import { getCollection } from "@/app/_lib/mongodb";
2025-01-27 02:58:43 +08:00
import { ObjectId } from "mongodb";
import { NextRequest } from "next/server";
import { verifySession } from "@/app/_lib/dal";
2025-02-17 18:17:12 +08:00
import { getLinkList } from "@/app/_lib/data/link";
2025-01-27 02:58:43 +08:00
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)
2025-02-17 18:17:12 +08:00
} catch {
2025-01-27 02:58:43 +08:00
return Response.error()
}
}
2025-02-07 19:02:22 +08:00
2025-01-27 02:58:43 +08:00
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
2025-02-07 19:02:22 +08:00
const collection = await getCollection('search')
2025-01-27 02:58:43 +08:00
collection.deleteOne({
_id: new ObjectId(slug)
})
return Response.json({ message: '删除成功' })
2025-02-17 18:17:12 +08:00
} catch {
2025-01-27 02:58:43 +08:00
return Response.error()
}
}