Added config support
This commit is contained in:
@@ -196,3 +196,18 @@ pub async fn get_task(id: &str) -> Result<TaskInfo, ApiError> {
|
||||
pub async fn get_config() -> Result<AppConfig, ApiError> {
|
||||
get_json(&format!("{BASE}/config")).await
|
||||
}
|
||||
|
||||
pub async fn save_config(config: &AppConfig) -> Result<AppConfig, ApiError> {
|
||||
let body = serde_json::to_string(config).map_err(|e| ApiError(e.to_string()))?;
|
||||
let resp = Request::put(&format!("{BASE}/config"))
|
||||
.header("Content-Type", "application/json")
|
||||
.body(&body)
|
||||
.map_err(|e| ApiError(e.to_string()))?
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| ApiError(e.to_string()))?;
|
||||
if !resp.ok() {
|
||||
return Err(ApiError(format!("HTTP {}", resp.status())));
|
||||
}
|
||||
resp.json().await.map_err(|e| ApiError(e.to_string()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user