mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-10-05 20:44:07 +08:00
- 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.
89 lines
2.7 KiB
Rust
89 lines
2.7 KiB
Rust
use crate::Result;
|
|
use axum::{extract::State, Json};
|
|
use serde::Deserialize;
|
|
|
|
use crate::store::{
|
|
DesktopSettings, PortSettings, ProxySettings, ProxySettingsInput, StatisticsStorage,
|
|
StatisticsStorageScope, TabSettings,
|
|
};
|
|
|
|
use super::{ControlService, ObservabilitySettings};
|
|
|
|
pub async fn get(State(service): State<ControlService>) -> Result<Json<ObservabilitySettings>> {
|
|
Ok(Json(service.observability().await?))
|
|
}
|
|
|
|
pub async fn update(
|
|
State(service): State<ControlService>,
|
|
Json(settings): Json<ObservabilitySettings>,
|
|
) -> Result<Json<ObservabilitySettings>> {
|
|
Ok(Json(service.set_observability(settings).await?))
|
|
}
|
|
|
|
pub async fn get_ports(State(service): State<ControlService>) -> Result<Json<PortSettings>> {
|
|
Ok(Json(service.ports().await?))
|
|
}
|
|
|
|
pub async fn update_ports(
|
|
State(service): State<ControlService>,
|
|
Json(settings): Json<PortSettings>,
|
|
) -> Result<Json<PortSettings>> {
|
|
Ok(Json(service.set_ports(settings).await?))
|
|
}
|
|
|
|
pub async fn get_storage(State(service): State<ControlService>) -> Result<Json<StatisticsStorage>> {
|
|
Ok(Json(service.statistics_storage().await?))
|
|
}
|
|
|
|
pub async fn clear_storage(
|
|
State(service): State<ControlService>,
|
|
input: Option<Json<ClearStorageInput>>,
|
|
) -> Result<Json<StatisticsStorage>> {
|
|
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>> {
|
|
Ok(Json(service.proxy_settings().await?))
|
|
}
|
|
|
|
pub async fn update_proxy(
|
|
State(service): State<ControlService>,
|
|
Json(settings): Json<ProxySettingsInput>,
|
|
) -> Result<Json<ProxySettings>> {
|
|
Ok(Json(service.set_proxy_settings(settings).await?))
|
|
}
|
|
|
|
pub async fn get_tab(State(service): State<ControlService>) -> Result<Json<TabSettings>> {
|
|
Ok(Json(service.tab_settings().await?))
|
|
}
|
|
|
|
pub async fn update_tab(
|
|
State(service): State<ControlService>,
|
|
Json(settings): Json<TabSettings>,
|
|
) -> Result<Json<TabSettings>> {
|
|
Ok(Json(service.set_tab_settings(settings).await?))
|
|
}
|
|
|
|
pub async fn get_desktop(State(service): State<ControlService>) -> Result<Json<DesktopSettings>> {
|
|
Ok(Json(service.desktop_settings().await?))
|
|
}
|
|
|
|
pub async fn update_desktop(
|
|
State(service): State<ControlService>,
|
|
Json(settings): Json<DesktopSettings>,
|
|
) -> Result<Json<DesktopSettings>> {
|
|
service.set_desktop_settings(settings).await?;
|
|
get_desktop(State(service)).await
|
|
}
|