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) -> Result> { Ok(Json(service.observability().await?)) } pub async fn update( State(service): State, Json(settings): Json, ) -> Result> { Ok(Json(service.set_observability(settings).await?)) } pub async fn get_ports(State(service): State) -> Result> { Ok(Json(service.ports().await?)) } pub async fn update_ports( State(service): State, Json(settings): Json, ) -> Result> { Ok(Json(service.set_ports(settings).await?)) } pub async fn get_storage(State(service): State) -> Result> { Ok(Json(service.statistics_storage().await?)) } pub async fn clear_storage( State(service): State, input: Option>, ) -> Result> { 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) -> Result> { Ok(Json(service.proxy_settings().await?)) } pub async fn update_proxy( State(service): State, Json(settings): Json, ) -> Result> { Ok(Json(service.set_proxy_settings(settings).await?)) } pub async fn get_tab(State(service): State) -> Result> { Ok(Json(service.tab_settings().await?)) } pub async fn update_tab( State(service): State, Json(settings): Json, ) -> Result> { Ok(Json(service.set_tab_settings(settings).await?)) } pub async fn get_desktop(State(service): State) -> Result> { Ok(Json(service.desktop_settings().await?)) } pub async fn update_desktop( State(service): State, Json(settings): Json, ) -> Result> { service.set_desktop_settings(settings).await?; get_desktop(State(service)).await }