diff --git a/app/app/(admin)/admin/page.tsx b/app/app/(admin)/admin/page.tsx index 29c830745..31d614e03 100644 --- a/app/app/(admin)/admin/page.tsx +++ b/app/app/(admin)/admin/page.tsx @@ -1,9 +1,15 @@ -// "use client"; import { Grid, Col, Card, Text, AreaChart, Metric } from "@tremor/react"; -// import UsageAnalysis from "./usage-analysis"; import UsageByModel from "./usage-by-model"; +import { getSession, ADMIN_LIST, isName } from "@/lib/auth"; +import { redirect } from "next/navigation"; + +export default async function AdminPage() { + const session = await getSession(); + if (!(session?.user?.name && ADMIN_LIST.includes(session.user.name))) { + // Replace '/dashboard' with the desired redirect path + redirect("/"); + } -export default function AdminPage() { return ( <> diff --git a/app/app/(admin)/admin/usage-by-model.tsx b/app/app/(admin)/admin/usage-by-model.tsx index af1aa575a..4a3f1f3ec 100644 --- a/app/app/(admin)/admin/usage-by-model.tsx +++ b/app/app/(admin)/admin/usage-by-model.tsx @@ -15,9 +15,6 @@ const UsageByModelChart = dynamic(() => import("./usage-by-model-chart"), { interface StringKeyedObject { [key: string]: { [key: string]: number }; } -// interface StringArray { -// strings: string[]; -// } type StringSet = Set; type StringArray = string[]; @@ -54,7 +51,6 @@ function HandleLogData( }), }; }); - console.log("看看", modelNameList); return { modelNameList, userNameList, @@ -64,12 +60,12 @@ function HandleLogData( export default async function UsageByModel() { // 今天日期的开始和结束 - var today = new Date(); + let currentTime = new Date(); // today = subMinutes(today, today.getTimezoneOffset()) const startOfTheDayInTimeZone = new Date( - today.getFullYear(), - today.getMonth(), - today.getDate(), + currentTime.getFullYear(), + currentTime.getMonth(), + currentTime.getDate(), 0, 0, 0, @@ -133,103 +129,6 @@ export default async function UsageByModel() { stack: "model", }; }), - - // [ - // { - // name: "总量", - // type: "bar", - // emphasis: { - // focus: "series", - // }, - // label: { - // show: true, - // position: "right", - // }, - // colorBy: "data", - // // progress: { - // // show: true - // // }, - // data: log_data.value, - // }, - // { - // name: 'Email', - // type: 'bar', - // stack: 'Ad', - // emphasis: { - // focus: 'series' - // }, - // data: [120, 132, 101, 134, 90, 230, 210] - // }, - // { - // name: 'Union Ads', - // type: 'bar', - // stack: 'Ad', - // emphasis: { - // focus: 'series' - // }, - // data: [220, 182, 191, 234, 290, 330, 310] - // }, - // { - // name: 'Video Ads', - // type: 'bar', - // stack: 'Ad', - // emphasis: { - // focus: 'series' - // }, - // data: [150, 232, 201, 154, 190, 330, 410] - // }, - // { - // name: 'Search Engine', - // type: 'bar', - // data: [862, 1018, 964, 1026, 1679, 1600, 1570], - // emphasis: { - // focus: 'series' - // }, - // // markLine: { - // // lineStyle: { - // // type: 'dashed' - // // }, - // // data: [[{ type: 'min' }, { type: 'max' }]] - // // } - // }, - // { - // name: 'Baidu', - // type: 'bar', - // barWidth: 5, - // stack: 'Search Engine', - // emphasis: { - // focus: 'series' - // }, - // data: [620, 732, 701, 734, 1090, 1130, 1120] - // }, - // { - // name: 'Google', - // type: 'bar', - // stack: 'Search Engine', - // emphasis: { - // focus: 'series' - // }, - // data: [120, 132, 101, 134, 290, 230, 220] - // }, - // { - // name: 'Bing', - // type: 'bar', - // stack: 'Search Engine', - // emphasis: { - // focus: 'series' - // }, - // data: [60, 72, 71, 74, 190, 130, 110] - // }, - // { - // name: 'Others', - // type: 'bar', - // stack: 'Search Engine', - // emphasis: { - // focus: 'series' - // }, - // data: [62, 82, 91, 84, 109, 110, 120] - // } - // ], }; return ( <> diff --git a/lib/auth.ts b/lib/auth.ts index 5df57af6e..a54cf690d 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -7,7 +7,12 @@ import prisma from "@/lib/prisma"; const SECURE_COOKIES:boolean = !!process.env.SECURE_COOKIES; - +export const DENY_LIST: string[] = [ + "suibian", "某某", "张三", "李四" +] +export const ADMIN_LIST: string[] = [ + "司金辉", "sijinhui", "sijinhui@qq.com" +] export const authOptions: NextAuthOptions = { // debug: !VERCEL_DEPLOYMENT, @@ -251,10 +256,7 @@ function isPinYin(input: string): boolean { export function isName(input: string): boolean { - const denyList = [ - "suibian", "某某", "张三", "李四" - ] - if (denyList.includes(input)) { + if (DENY_LIST.includes(input)) { return false; } return isEmail(input) || isHanZi(input) || isPinYin(input); diff --git a/middleware.ts b/middleware.ts index 4c7990da2..2ecfa0bf6 100644 --- a/middleware.ts +++ b/middleware.ts @@ -8,6 +8,10 @@ export default async function middleware(req: NextRequest) { const path = `${url.pathname}${ searchParams.length > 0 ? `?${searchParams}` : "" }`; + // 直接将/app/下面路由重定向到顶层 + if (path.startsWith('/app')) { + return NextResponse.redirect(new URL(path.replace('/app', ''), req.url), 301); + } const session = await getToken({ req }); @@ -21,15 +25,7 @@ export default async function middleware(req: NextRequest) { } return NextResponse.redirect(new URL("/login", req.url)); } else if (session) { - if (path.startsWith("/login") || path.startsWith('/app/login')) return NextResponse.redirect(new URL("/", req.url)); - // admin 认证 - const admin_user = ["sijinhui", "司金辉"] - // @ts-ignore - if ((path.startsWith("/admin") || path.startsWith("/app/admin")) && !admin_user.includes(session?.user?.name)) { - return NextResponse.redirect(new URL("/", req.url)); - } else { - console.log('[admin]', session?.user) - } + if (path.startsWith("/login")) return NextResponse.redirect(new URL("/", req.url)); } if (path == '/login') {