Skip to content

Commit

Permalink
fix: use MAX_HISTORY_LENGTH config
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster1963 committed Jan 3, 2025
1 parent 6ba7747 commit 6bc7e0d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
18 changes: 11 additions & 7 deletions app/(main)/ClientComponents/detail/ServerDetailChartClient.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"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 { ServerDetailChartLoading } from "@/components/loading/ServerDetailLoading"
import AnimatedCircularProgressBar from "@/components/ui/animated-circular-progress-bar"
Expand Down Expand Up @@ -122,7 +126,7 @@ function CpuChart({ history, data }: { history: ServerDataWithTimestamp[]; data:
} else {
newData = [...cpuChartData, { timeStamp: timestamp, cpu: cpu }]
}
if (newData.length > 30) {
if (newData.length > MAX_HISTORY_LENGTH) {
newData.shift()
}
setCpuChartData(newData)
Expand Down Expand Up @@ -245,7 +249,7 @@ function ProcessChart({
} else {
newData = [...processChartData, { timeStamp: timestamp, process: process }]
}
if (newData.length > 30) {
if (newData.length > MAX_HISTORY_LENGTH) {
newData.shift()
}
setProcessChartData(newData)
Expand Down Expand Up @@ -349,7 +353,7 @@ function MemChart({ data, history }: { data: NezhaAPISafe; history: ServerDataWi
} else {
newData = [...memChartData, { timeStamp: timestamp, mem: mem, swap: swap }]
}
if (newData.length > 30) {
if (newData.length > MAX_HISTORY_LENGTH) {
newData.shift()
}
setMemChartData(newData)
Expand Down Expand Up @@ -502,7 +506,7 @@ function DiskChart({ data, history }: { data: NezhaAPISafe; history: ServerDataW
} else {
newData = [...diskChartData, { timeStamp: timestamp, disk: disk }]
}
if (newData.length > 30) {
if (newData.length > MAX_HISTORY_LENGTH) {
newData.shift()
}
setDiskChartData(newData)
Expand Down Expand Up @@ -631,7 +635,7 @@ function NetworkChart({
} else {
newData = [...networkChartData, { timeStamp: timestamp, upload: up, download: down }]
}
if (newData.length > 30) {
if (newData.length > MAX_HISTORY_LENGTH) {
newData.shift()
}
setNetworkChartData(newData)
Expand Down Expand Up @@ -779,7 +783,7 @@ function ConnectChart({
} else {
newData = [...connectChartData, { timeStamp: timestamp, tcp: tcp, udp: udp }]
}
if (newData.length > 30) {
if (newData.length > MAX_HISTORY_LENGTH) {
newData.shift()
}
setConnectChartData(newData)
Expand Down
2 changes: 1 addition & 1 deletion app/lib/server-data-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface ServerDataContextType {

const ServerDataContext = createContext<ServerDataContextType | undefined>(undefined)

const MAX_HISTORY_LENGTH = 30
export const MAX_HISTORY_LENGTH = 30

export function ServerDataProvider({ children }: { children: ReactNode }) {
const [history, setHistory] = useState<ServerDataWithTimestamp[]>([])
Expand Down
3 changes: 1 addition & 2 deletions auth.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import getEnv from "@/lib/env-entry"
import NextAuth from "next-auth"
import CredentialsProvider from "next-auth/providers/credentials"

import getEnv from "./lib/env-entry"

export const { handlers, signIn, signOut, auth } = NextAuth({
secret: process.env.AUTH_SECRET ?? "this_is_nezha_dash_web_secret",
trustHost: (process.env.AUTH_TRUST_HOST as boolean | undefined) ?? true,
Expand Down

0 comments on commit 6bc7e0d

Please sign in to comment.