From eb751fdb0b4d463cc06ea462da47b1ab19979053 Mon Sep 17 00:00:00 2001 From: xiaji Date: Thu, 16 Apr 2026 22:53:52 +0800 Subject: [PATCH] Fix shutdown API, update connection state after shutdown --- src/api.rs | 18 ++++-------------- src/gui.rs | 6 ++++-- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/api.rs b/src/api.rs index e4a10f6..99d6be8 100644 --- a/src/api.rs +++ b/src/api.rs @@ -253,30 +253,20 @@ impl ProxmoxClient { pub async fn shutdown_node(&self, node: &str) -> Result { let url = format!("{}/nodes/{}/status", self.base_url, node); - println!("[API] 关机请求: POST {}", url); - println!("[API] Headers: Authorization={}", self.auth_header()); let resp = self.client .post(&url) .header("Authorization", self.auth_header()) - .header("Content-Type", "application/json") - .json(&serde_json::json!({"command": "shutdown"})) + .form(&[("command", "shutdown")]) .send() .await - .map_err(|e| { - let err = format!("网络错误: {}", e); - println!("[API] {}", err); - err - })?; + .map_err(|e| format!("网络错误: {}", e))?; let status = resp.status(); - let body = resp.text().await.unwrap_or_default(); - println!("[API] 响应状态: {}", status); - println!("[API] 响应内容: {}", body); - if !status.is_success() { + let body = resp.text().await.unwrap_or_default(); return Err(format!("HTTP {}: {}", status, body)); } - Ok(body) + Ok("ok".to_string()) } } \ No newline at end of file diff --git a/src/gui.rs b/src/gui.rs index 7c7726c..733d055 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -530,8 +530,10 @@ impl eframe::App for App { if let Some(c) = client.as_ref() { match c.shutdown_node(&node).await { Ok(response) => { - state.write().unwrap().add_log("✓ 关机命令发送成功"); - state.write().unwrap().add_log(&format!("响应: {}", response)); + let mut s = state.write().unwrap(); + s.add_log("✓ 关机命令发送成功"); + s.add_log(&format!("响应: {}", response)); + s.is_connected = false; } Err(e) => { state.write().unwrap().add_log(&format!("✗ 关机失败: {}", e));