feat(web): storage section on status page (FIX-5)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-09-29 19:37:11 +08:00
1 parent 2c9e5a1d00
commit 6aaf8c0704
4 files changed
+441 -5

No files matched your search

+33 -3
View File
@@ -1,9 +1,16 @@
import { useQuery } from "@tanstack/react-query";
import type { SystemHealth, SystemHealthHistory } from "@umt/contracts";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import type {
StorageCleanupResult,
StorageCleanupTarget,
SystemHealth,
SystemHealthHistory,
SystemStorage,
} from "@umt/contracts";
import { apiData } from "~/lib/api.ts";
import { qk } from "~/lib/query-keys.ts";
// 进程与健康(W9-I):GET /system/health、/system/health/history,仅 admin。
// 进程与健康(W9-I):GET /system/health、/system/health/history;存储(CACHE-2):GET /system/storage、
// POST /system/storage/cleanup/{target}。仅 admin。
export function useSystemHealth(refetchMs = 15_000) {
return useQuery({
@@ -20,3 +27,26 @@ export function useSystemHealthHistory(hours: number) {
refetchInterval: 60_000,
});
}
/** 存储明细:目录用量服务端缓存 5 分钟,这里 1 分钟刷新一次 */
export function useSystemStorage() {
return useQuery({
queryKey: qk.sub("system", "storage"),
queryFn: ({ signal }) => apiData<SystemStorage>("/system/storage", { signal }),
refetchInterval: 60_000,
});
}
/** 手动清理:把对应的维护任务排入立即执行 */
export function useStorageCleanup() {
const qc = useQueryClient();
return useMutation({
mutationFn: (target: StorageCleanupTarget) =>
apiData<StorageCleanupResult>("/system/storage/cleanup/{target}", {
method: "POST",
pathParams: { target },
body: {},
}),
onSuccess: () => void qc.invalidateQueries({ queryKey: qk.sub("system", "storage") }),
});
}