fix: use MAX_HISTORY_LENGTH config

This commit is contained in:
hamster1963 2025-01-04 00:21:42 +08:00
parent 6ba7747dd6
commit 6bc7e0de0e
3 changed files with 13 additions and 10 deletions

View File

@ -1,6 +1,10 @@
"use client" "use client"
import { ServerDataWithTimestamp, useServerData } from "@/app/lib/server-data-context" import {
MAX_HISTORY_LENGTH,
ServerDataWithTimestamp,
useServerData,
} from "@/app/lib/server-data-context"
import { NezhaAPISafe } from "@/app/types/nezha-api" import { NezhaAPISafe } from "@/app/types/nezha-api"
import { ServerDetailChartLoading } from "@/components/loading/ServerDetailLoading" import { ServerDetailChartLoading } from "@/components/loading/ServerDetailLoading"
import AnimatedCircularProgressBar from "@/components/ui/animated-circular-progress-bar" import AnimatedCircularProgressBar from "@/components/ui/animated-circular-progress-bar"
@ -122,7 +126,7 @@ function CpuChart({ history, data }: { history: ServerDataWithTimestamp[]; data:
} else { } else {
newData = [...cpuChartData, { timeStamp: timestamp, cpu: cpu }] newData = [...cpuChartData, { timeStamp: timestamp, cpu: cpu }]
} }
if (newData.length > 30) { if (newData.length > MAX_HISTORY_LENGTH) {
newData.shift() newData.shift()
} }
setCpuChartData(newData) setCpuChartData(newData)
@ -245,7 +249,7 @@ function ProcessChart({
} else { } else {
newData = [...processChartData, { timeStamp: timestamp, process: process }] newData = [...processChartData, { timeStamp: timestamp, process: process }]
} }
if (newData.length > 30) { if (newData.length > MAX_HISTORY_LENGTH) {
newData.shift() newData.shift()
} }
setProcessChartData(newData) setProcessChartData(newData)
@ -349,7 +353,7 @@ function MemChart({ data, history }: { data: NezhaAPISafe; history: ServerDataWi
} else { } else {
newData = [...memChartData, { timeStamp: timestamp, mem: mem, swap: swap }] newData = [...memChartData, { timeStamp: timestamp, mem: mem, swap: swap }]
} }
if (newData.length > 30) { if (newData.length > MAX_HISTORY_LENGTH) {
newData.shift() newData.shift()
} }
setMemChartData(newData) setMemChartData(newData)
@ -502,7 +506,7 @@ function DiskChart({ data, history }: { data: NezhaAPISafe; history: ServerDataW
} else { } else {
newData = [...diskChartData, { timeStamp: timestamp, disk: disk }] newData = [...diskChartData, { timeStamp: timestamp, disk: disk }]
} }
if (newData.length > 30) { if (newData.length > MAX_HISTORY_LENGTH) {
newData.shift() newData.shift()
} }
setDiskChartData(newData) setDiskChartData(newData)
@ -631,7 +635,7 @@ function NetworkChart({
} else { } else {
newData = [...networkChartData, { timeStamp: timestamp, upload: up, download: down }] newData = [...networkChartData, { timeStamp: timestamp, upload: up, download: down }]
} }
if (newData.length > 30) { if (newData.length > MAX_HISTORY_LENGTH) {
newData.shift() newData.shift()
} }
setNetworkChartData(newData) setNetworkChartData(newData)
@ -779,7 +783,7 @@ function ConnectChart({
} else { } else {
newData = [...connectChartData, { timeStamp: timestamp, tcp: tcp, udp: udp }] newData = [...connectChartData, { timeStamp: timestamp, tcp: tcp, udp: udp }]
} }
if (newData.length > 30) { if (newData.length > MAX_HISTORY_LENGTH) {
newData.shift() newData.shift()
} }
setConnectChartData(newData) setConnectChartData(newData)

View File

@ -20,7 +20,7 @@ interface ServerDataContextType {
const ServerDataContext = createContext<ServerDataContextType | undefined>(undefined) const ServerDataContext = createContext<ServerDataContextType | undefined>(undefined)
const MAX_HISTORY_LENGTH = 30 export const MAX_HISTORY_LENGTH = 30
export function ServerDataProvider({ children }: { children: ReactNode }) { export function ServerDataProvider({ children }: { children: ReactNode }) {
const [history, setHistory] = useState<ServerDataWithTimestamp[]>([]) const [history, setHistory] = useState<ServerDataWithTimestamp[]>([])

View File

@ -1,8 +1,7 @@
import getEnv from "@/lib/env-entry"
import NextAuth from "next-auth" import NextAuth from "next-auth"
import CredentialsProvider from "next-auth/providers/credentials" import CredentialsProvider from "next-auth/providers/credentials"
import getEnv from "./lib/env-entry"
export const { handlers, signIn, signOut, auth } = NextAuth({ export const { handlers, signIn, signOut, auth } = NextAuth({
secret: process.env.AUTH_SECRET ?? "this_is_nezha_dash_web_secret", secret: process.env.AUTH_SECRET ?? "this_is_nezha_dash_web_secret",
trustHost: (process.env.AUTH_TRUST_HOST as boolean | undefined) ?? true, trustHost: (process.env.AUTH_TRUST_HOST as boolean | undefined) ?? true,