Files
rustfs-console/hooks/use-system.ts
T
安正超 6f1193f6e4 chore: replace codebase with Next.js version (console-new) (#46)
* chore: replace codebase with Next.js version (console-new)

- Migrate from Nuxt/Vue to Next.js/React
- Same repo, dev-pr branch has shared history with main for PR

* chore: wip

* ci: pin pnpm to latest in workflows, packageManager 10.19.0

* ci: use pnpm version from package.json only (fix version mismatch)

* fix: CI - add root page redirect, fix TS types and lint (api-client, aws4fetch, upload-task, hooks)

* fix(ci): add type-check script for TypeScript Check job

* fix(ci): resolve Code Formatting job - ESLint errors (setState-in-effect, refs, static-components, preserve-memoization)

* fix(ci): add lint:fix script for quality workflow Auto-fix step

* fix(ci): add SVG module type declaration for TypeScript Check
2026-02-01 21:23:31 +08:00

47 lines
1.1 KiB
TypeScript

"use client"
import { useCallback } from "react"
import { useApi } from "@/contexts/api-context"
export function useSystem() {
const api = useApi()
const getSystemInfo = useCallback(async () => {
return api.get("/info")
}, [api])
const getStorageInfo = useCallback(async () => {
return api.get("/storageinfo")
}, [api])
const getDataUsageInfo = useCallback(async () => {
return api.get("/datausageinfo")
}, [api])
const getSystemMetrics = useCallback(async () => {
try {
let merged: Record<string, unknown> = {}
for await (const data of api.streamRequest("/metrics")) {
merged = { ...merged, ...data }
}
if (Object.keys(merged).length > 0) return merged
} catch {
// Fallback: try regular GET if streaming fails (e.g. API returns single JSON)
}
const res = await api.get("/metrics")
return (res as Record<string, unknown>) ?? {}
}, [api])
const getLicense = useCallback(async () => {
return api.get("/license")
}, [api])
return {
getSystemInfo,
getStorageInfo,
getDataUsageInfo,
getSystemMetrics,
getLicense,
}
}