mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-01 23:56:39 +08:00
修复打包后页面不能刷新的问题
This commit is contained in:
parent
59f91a1f21
commit
f4b9741bcb
@ -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 (
|
||||
<>
|
||||
<Grid numItems={1} numItemsSm={2} numItemsLg={3} className="gap-2">
|
||||
|
@ -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<string>;
|
||||
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 (
|
||||
<>
|
||||
|
12
lib/auth.ts
12
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);
|
||||
|
@ -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') {
|
||||
|
Loading…
Reference in New Issue
Block a user