This commit is contained in:
expdsn 2025-01-27 02:58:43 +08:00
parent 4317963775
commit df92d99a51
8 changed files with 242 additions and 29 deletions

View File

@ -40,7 +40,7 @@ export async function login(state: FormState, formData: FormData) {
await createSession(user._id)
// 5. Redirect user
redirect('/admin')
redirect('/admin')p
}
export async function logout() {

View File

@ -6,6 +6,7 @@ export type SearchTypeItem = {
name: string;
key: string;
includes: string[];
_id: string;
priority: number;
}
@ -13,7 +14,7 @@ export type SearchWayItemType = {
label: string;
value: string;
fullName: string;
key: string;
_id: string;
}
export async function getSearchTypeList({ page = 1, pageSize = 9999 }: {
@ -68,12 +69,3 @@ export async function getSearchWayList({ page = 1, pageSize = 9999 }: {
list
}
}
export async function addSearchType(searchTypeItem: SearchTypeItem) {
const collection = await getCollection('search-type')
collection.insertOne(searchTypeItem)
}
export async function addSearchWay(searchItem: SearchWayItemType) {
const collection = await getCollection('search')
collection.insertOne(searchItem)
}

View File

@ -0,0 +1,58 @@
import { SearchTypeItem, SearchWayItemType } from "@/app/_lib/data/search";
import { mRequest } from "@/app/_lib/request";
import { useAntdTable, useRequest } from "ahooks";
import { Button, Card, Space, Table } from "antd";
export default function Page() {
const searchWayList = useRequest(async () => mRequest('GET', "/api/search"))
const { data } = useAntdTable(async () => mRequest<{
total: number;
list: SearchTypeItem[]
}>('GET', "/api/"))
return <Space>
{/*
<Card title="搜索分类管理" extra={<Button type="primary"></Button>}>
<Table<SearchTypeItem>
columns={[
{
title: '分类名称',
dataIndex: 'name'
},
{
title: '标示符',
dataIndex: 'key',
},
{
title:
}
]}
>
</Table>
</Card> */}
<Card title="搜索引擎管理">
<Table<SearchWayItemType>
columns={[
{
title: '名称',
dataIndex: 'label',
},
{
title: '全称',
dataIndex: 'fullName',
},
{
title: '搜索链接',
dataIndex: 'value'
}
]}
>
</Table>
</Card>
</Space>
}

View File

@ -0,0 +1,39 @@
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('link')
collection.deleteOne({
_id: new ObjectId(slug)
})
return Response.json({ message: '删除成功' })
} catch (e) {
return Response.error()
}
}

61
app/api/search/route.ts Normal file
View File

@ -0,0 +1,61 @@
import { verifySession } from "@/app/_lib/dal";
import { Link } from "@/app/_lib/data/link";
import { getSearchWayList } from "@/app/_lib/data/search";
import { User } from "@/app/_lib/data/user";
import { getCollection, getDb } from "@/app/_lib/mongodb";
import { message } from "antd";
import bcrypt from 'bcrypt';
import { ObjectId } from "mongodb";
import { NextRequest } from "next/server";
export async function GET(req: NextRequest) {
try {
// Check if the user is authenticated
const page = parseInt(req.nextUrl.searchParams.get('page') || '1') || 1;
const pageSize = parseInt(req.nextUrl.searchParams.get('pageSize') || '10') || 10;
const res = getSearchWayList({ page, pageSize })
return Response.json(res)
} catch (e) {
return Response.error()
}
}
export async function POST(req: NextRequest) {
try {
const session = await verifySession()
// Check if the user is authenticated
if (!session) {
// User is not authenticated
return new Response(null, { status: 401 })
}
// 获取待插入的对象
const link = await req.json()
const collection = await getCollection('search')
await collection.insertOne(link)
return Response.json({ message: '成功' })
} catch (e) {
return Response.error()
}
}
export async function PUT(req: NextRequest) {
try {
const session = await verifySession()
// Check if the user is authenticated
if (!session) {
// User is not authenticated
return new Response(null, { status: 401 })
}
// 获取待更新的对象
const link = await req.json() as Link
const collection = await getCollection('link')
await collection.replaceOne({ _id: new ObjectId(link._id) }, { ...link, _id: new ObjectId(link._id) })
return Response.json({ message: '成功' })
} catch (e) {
return Response.error()
}
}

View File

@ -0,0 +1,25 @@
import { getCollection, getDb } from "@/app/_lib/mongodb";
import { ObjectId } from "mongodb";
import { NextRequest } from "next/server";
import { verifySession } from "@/app/_lib/dal";
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-type')
collection.deleteOne({
_id: new ObjectId(slug)
})
return Response.json({ message: '删除成功' })
} catch (e) {
return Response.error()
}
}

View File

@ -0,0 +1,56 @@
import { verifySession } from "@/app/_lib/dal";
import { getSearchTypeList, SearchTypeItem } from "@/app/_lib/data/search";
import { getCollection } from "@/app/_lib/mongodb";
import { ObjectId } from "mongodb";
import { NextRequest } from "next/server";
export async function GET(req: NextRequest) {
try {
// Check if the user is authenticated
const page = parseInt(req.nextUrl.searchParams.get('page') || '1') || 1;
const pageSize = parseInt(req.nextUrl.searchParams.get('pageSize') || '10') || 10;
const res = getSearchTypeList({ page, pageSize })
return Response.json(res)
} catch (e) {
return Response.error()
}
}
export async function POST(req: NextRequest) {
try {
const session = await verifySession()
// Check if the user is authenticated
if (!session) {
// User is not authenticated
return new Response(null, { status: 401 })
}
const collection = await getCollection('search-type')
const item = req.json()
const res = collection.insertOne(item)
return Response.json(res)
} catch (e) {
return Response.error()
}
}
export async function PUT(req: NextRequest) {
try {
const session = await verifySession()
// Check if the user is authenticated
if (!session) {
// User is not authenticated
return new Response(null, { status: 401 })
}
// 获取待更新的对象
const collection = await getCollection('search-type')
const item = await req.json() as SearchTypeItem
const res = await collection.replaceOne({ _id: new ObjectId(item._id) }, { ...item, _id: new ObjectId(item._id) })
return Response.json(res)
} catch (e) {
return Response.error()
}
}

View File

@ -1,18 +0,0 @@
import { getCollection, getDb } from "@/app/_lib/mongodb";
import bcrypt from 'bcrypt';
import { headers } from "next/headers";
import { NextRequest } from "next/server";
export async function GET(request: NextRequest) {
try {
const referer = request.nextUrl.searchParams.get('page')
return Response.json({
referer
})
} catch (e) {
console.log(e);
return Response.json('遇到了一些问题')
}
}