feat(api): enhance statistics storage management with scope options

- Introduced a new type `StatisticsStorageScope` to specify the scope for clearing statistics.
- Updated the `clearStatisticsStorage` API method to accept a scope parameter, allowing for selective clearing of detailed records or all statistics.
- Modified the demo API to handle the new scope parameter appropriately.
- Updated the SettingsPage component to include a selection for clearing scope, enhancing user control over statistics management.
- Added new translations for the updated messages related to statistics clearing in both English and Chinese.
This commit is contained in:
leookun committed 2026-08-28 10:18:11 +08:00
1 parent 217f984112
commit 71ddf71ec1
15 files changed
+514 -111

No files matched your search

+4
View File
@@ -565,6 +565,10 @@ impl ControlService {
self.store.clear_statistics_storage().await
}
pub async fn clear_all_statistics_storage(&self) -> Result<StatisticsStorage> {
self.store.clear_all_statistics_storage().await
}
pub async fn proxy_settings(&self) -> Result<ProxySettings> {
self.store.proxy_settings().await
}
+15 -2
View File
@@ -1,9 +1,10 @@
use crate::Result;
use axum::{extract::State, Json};
use serde::Deserialize;
use crate::store::{
DesktopSettings, PortSettings, ProxySettings, ProxySettingsInput, StatisticsStorage,
TabSettings,
StatisticsStorageScope, TabSettings,
};
use super::{ControlService, ObservabilitySettings};
@@ -36,8 +37,20 @@ pub async fn get_storage(State(service): State<ControlService>) -> Result<Json<S
pub async fn clear_storage(
State(service): State<ControlService>,
input: Option<Json<ClearStorageInput>>,
) -> Result<Json<StatisticsStorage>> {
Ok(Json(service.clear_statistics_storage().await?))
let scope = input.map(|Json(input)| input.scope).unwrap_or_default();
let storage = match scope {
StatisticsStorageScope::Details => service.clear_statistics_storage().await?,
StatisticsStorageScope::All => service.clear_all_statistics_storage().await?,
};
Ok(Json(storage))
}
#[derive(Deserialize)]
pub struct ClearStorageInput {
#[serde(default)]
pub scope: StatisticsStorageScope,
}
pub async fn get_proxy(State(service): State<ControlService>) -> Result<Json<ProxySettings>> {