This commit is contained in:
fengchuanhn@gmail.com
2026-05-17 22:05:34 +08:00
parent 9dfeaa9e18
commit c70995fbc9
14 changed files with 428 additions and 148 deletions

View File

@@ -237,34 +237,20 @@ impl AppConfig {
}
async fn fetch_from_server(token: &str) -> Result<HashMap<String, String>, AppConfigError> {
let base = api_base().trim_end_matches('/').to_string();
let url = format!("{base}/api/v1/appConfig");
let mut headers = HashMap::new();
headers.insert(
"Authorization".to_string(),
format!("Bearer {}", token.trim()),
);
let client = reqwest::Client::builder()
.timeout(std::time::Duration::from_secs(30))
.build()
.map_err(|e| AppConfigError::Fetch(e.to_string()))?;
let res = client
.get(&url)
.header("Authorization", format!("Bearer {}", token.trim()))
.send()
let (status, v) = crate::api_client::request_json("GET", "/appConfig", None, headers)
.await
.map_err(|e| AppConfigError::Fetch(e.to_string()))?;
.map_err(|e| AppConfigError::Fetch(e))?;
let status = res.status();
let body = res
.text()
.await
.map_err(|e| AppConfigError::Fetch(e.to_string()))?;
if status == reqwest::StatusCode::UNAUTHORIZED {
if status == 401 {
return Err(AppConfigError::Fetch("未认证或令牌已失效".into()));
}
let v: Value =
serde_json::from_str(&body).map_err(|e| AppConfigError::Fetch(format!("响应非 JSON: {e}")))?;
let ok = v.get("ok").and_then(|x| x.as_bool()).unwrap_or(false);
if !ok {
let msg = v