mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-03 00:26:40 +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 { Grid, Col, Card, Text, AreaChart, Metric } from "@tremor/react";
|
||||||
// import UsageAnalysis from "./usage-analysis";
|
|
||||||
import UsageByModel from "./usage-by-model";
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Grid numItems={1} numItemsSm={2} numItemsLg={3} className="gap-2">
|
<Grid numItems={1} numItemsSm={2} numItemsLg={3} className="gap-2">
|
||||||
|
@ -15,9 +15,6 @@ const UsageByModelChart = dynamic(() => import("./usage-by-model-chart"), {
|
|||||||
interface StringKeyedObject {
|
interface StringKeyedObject {
|
||||||
[key: string]: { [key: string]: number };
|
[key: string]: { [key: string]: number };
|
||||||
}
|
}
|
||||||
// interface StringArray {
|
|
||||||
// strings: string[];
|
|
||||||
// }
|
|
||||||
|
|
||||||
type StringSet = Set<string>;
|
type StringSet = Set<string>;
|
||||||
type StringArray = string[];
|
type StringArray = string[];
|
||||||
@ -54,7 +51,6 @@ function HandleLogData(
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
console.log("看看", modelNameList);
|
|
||||||
return {
|
return {
|
||||||
modelNameList,
|
modelNameList,
|
||||||
userNameList,
|
userNameList,
|
||||||
@ -64,12 +60,12 @@ function HandleLogData(
|
|||||||
|
|
||||||
export default async function UsageByModel() {
|
export default async function UsageByModel() {
|
||||||
// 今天日期的开始和结束
|
// 今天日期的开始和结束
|
||||||
var today = new Date();
|
let currentTime = new Date();
|
||||||
// today = subMinutes(today, today.getTimezoneOffset())
|
// today = subMinutes(today, today.getTimezoneOffset())
|
||||||
const startOfTheDayInTimeZone = new Date(
|
const startOfTheDayInTimeZone = new Date(
|
||||||
today.getFullYear(),
|
currentTime.getFullYear(),
|
||||||
today.getMonth(),
|
currentTime.getMonth(),
|
||||||
today.getDate(),
|
currentTime.getDate(),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@ -133,103 +129,6 @@ export default async function UsageByModel() {
|
|||||||
stack: "model",
|
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 (
|
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;
|
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 = {
|
export const authOptions: NextAuthOptions = {
|
||||||
// debug: !VERCEL_DEPLOYMENT,
|
// debug: !VERCEL_DEPLOYMENT,
|
||||||
@ -251,10 +256,7 @@ function isPinYin(input: string): boolean {
|
|||||||
|
|
||||||
|
|
||||||
export function isName(input: string): boolean {
|
export function isName(input: string): boolean {
|
||||||
const denyList = [
|
if (DENY_LIST.includes(input)) {
|
||||||
"suibian", "某某", "张三", "李四"
|
|
||||||
]
|
|
||||||
if (denyList.includes(input)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return isEmail(input) || isHanZi(input) || isPinYin(input);
|
return isEmail(input) || isHanZi(input) || isPinYin(input);
|
||||||
|
@ -8,6 +8,10 @@ export default async function middleware(req: NextRequest) {
|
|||||||
const path = `${url.pathname}${
|
const path = `${url.pathname}${
|
||||||
searchParams.length > 0 ? `?${searchParams}` : ""
|
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 });
|
const session = await getToken({ req });
|
||||||
|
|
||||||
@ -21,15 +25,7 @@ export default async function middleware(req: NextRequest) {
|
|||||||
}
|
}
|
||||||
return NextResponse.redirect(new URL("/login", req.url));
|
return NextResponse.redirect(new URL("/login", req.url));
|
||||||
} else if (session) {
|
} else if (session) {
|
||||||
if (path.startsWith("/login") || path.startsWith('/app/login')) return NextResponse.redirect(new URL("/", req.url));
|
if (path.startsWith("/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 == '/login') {
|
if (path == '/login') {
|
||||||
|
Loading…
Reference in New Issue
Block a user