From d9267eea4151d0215276155902c7b4fd4864573f Mon Sep 17 00:00:00 2001 From: leokun Date: Sun, 20 Sep 2026 11:15:58 +0800 Subject: [PATCH] refactor(storage): show row counts instead of byte size --- apps/desktop/src/demo/api.ts | 6 +- .../src/features/settings/SettingsPage.tsx | 27 ++- apps/desktop/src/i18n/generated/catalog.json | 159 ++++++++++-------- apps/desktop/src/i18n/locales/en-US.json | 1 + apps/desktop/src/i18n/locales/pt-BR.json | 1 + apps/desktop/src/i18n/locales/zh-CN.json | 1 + apps/desktop/src/shared/api.ts | 1 - server/src/store/storage.rs | 34 +--- 8 files changed, 106 insertions(+), 124 deletions(-) diff --git a/apps/desktop/src/demo/api.ts b/apps/desktop/src/demo/api.ts index e5b8e80..cc21e8f 100644 --- a/apps/desktop/src/demo/api.ts +++ b/apps/desktop/src/demo/api.ts @@ -94,7 +94,7 @@ let proxySettings: ProxySettings = { has_password: false, }; let tabSettings: TabSettings = { mode: "public", address: "" }; -let storage: StatisticsStorage = { bytes: 26_004_480, call_count: calls.length, trace_count: calls.length }; +let storage: StatisticsStorage = { call_count: calls.length, trace_count: calls.length }; export function installDemoApi() { const nativeFetch = window.fetch.bind(window); @@ -151,9 +151,7 @@ export function installDemoApi() { if (path === "/settings/storage/statistics" && method === "GET") return json(storage); if (path === "/settings/storage/statistics") { const scope = (body as { scope?: string } | null)?.scope ?? "details"; - storage = scope === "all" - ? { bytes: 0, call_count: 0, trace_count: 0 } - : { ...storage, bytes: 0 }; + storage = scope === "all" ? { call_count: 0, trace_count: 0 } : storage; return json(storage); } if (path === "/settings/proxy" && method === "GET") return json(proxySettings); diff --git a/apps/desktop/src/features/settings/SettingsPage.tsx b/apps/desktop/src/features/settings/SettingsPage.tsx index 700c416..212c2fd 100644 --- a/apps/desktop/src/features/settings/SettingsPage.tsx +++ b/apps/desktop/src/features/settings/SettingsPage.tsx @@ -40,13 +40,16 @@ export function SettingsPage() { const [editingTab, setEditingTab] = useState(false); const [savingTab, setSavingTab] = useState(false); useEffect(() => { - void Promise.all([api.statisticsStorage(), api.proxySettings(), api.tabSettings()]).then(([nextStorage, nextProxy, nextTab]) => { - setStorage(nextStorage); - setOutboundProxy(nextProxy); - setProxyDraft({ mode: nextProxy.mode, address: nextProxy.address, auth_enabled: nextProxy.auth_enabled, username: nextProxy.username, password: "" }); - setTabSettings(nextTab); - setTabDraft(nextTab); - }).catch((cause) => message(cause instanceof Error ? cause.message : String(cause))); + const report = (cause: unknown) => message(cause instanceof Error ? cause.message : String(cause)); + void api.statisticsStorage().then(setStorage).catch(report); + void api.proxySettings().then((next) => { + setOutboundProxy(next); + setProxyDraft({ mode: next.mode, address: next.address, auth_enabled: next.auth_enabled, username: next.username, password: "" }); + }).catch(report); + void api.tabSettings().then((next) => { + setTabSettings(next); + setTabDraft(next); + }).catch(report); }, [message]); useEffect(() => { setProxyPort(String(ports.proxy_port)); @@ -149,14 +152,6 @@ export function SettingsPage() { setSavingTab(false); } }; - const formatBytes = (bytes: number) => { - if (bytes < 1024) return `${bytes} B`; - const units = ["KB", "MB", "GB", "TB"]; - let value = bytes / 1024; - let unit = 0; - while (value >= 1024 && unit < units.length - 1) { value /= 1024; unit += 1; } - return `${value < 10 ? value.toFixed(1) : Math.round(value)} ${units[unit]}`; - }; const clearTitle = clearScope === "all" ? t("确定要清理全部统计数据吗?") : t("确定要清理详细记录吗?"); const clearDescription = clearScope === "all" ? t("所有调用汇总、详细内容和追踪记录都会被删除。模型配置、CA 和应用设置不会受到影响,此操作无法撤销。") @@ -283,7 +278,7 @@ export function SettingsPage() {
{t("统计数据")} - {storage ? formatBytes(storage.bytes) : t("计算中…")} + {storage ? t("调用记录 {calls} 条 · 追踪记录 {traces} 条", { calls: storage.call_count, traces: storage.trace_count }) : t("计算中…")}