Fix shutdown API, update connection state after shutdown

This commit is contained in:
xiaji
2026-04-16 22:53:52 +08:00
parent 15334459be
commit eb751fdb0b
2 changed files with 8 additions and 16 deletions

View File

@@ -253,30 +253,20 @@ impl ProxmoxClient {
pub async fn shutdown_node(&self, node: &str) -> Result<String, String> { pub async fn shutdown_node(&self, node: &str) -> Result<String, String> {
let url = format!("{}/nodes/{}/status", self.base_url, node); let url = format!("{}/nodes/{}/status", self.base_url, node);
println!("[API] 关机请求: POST {}", url);
println!("[API] Headers: Authorization={}", self.auth_header());
let resp = self.client let resp = self.client
.post(&url) .post(&url)
.header("Authorization", self.auth_header()) .header("Authorization", self.auth_header())
.header("Content-Type", "application/json") .form(&[("command", "shutdown")])
.json(&serde_json::json!({"command": "shutdown"}))
.send() .send()
.await .await
.map_err(|e| { .map_err(|e| format!("网络错误: {}", e))?;
let err = format!("网络错误: {}", e);
println!("[API] {}", err);
err
})?;
let status = resp.status(); let status = resp.status();
let body = resp.text().await.unwrap_or_default();
println!("[API] 响应状态: {}", status);
println!("[API] 响应内容: {}", body);
if !status.is_success() { if !status.is_success() {
let body = resp.text().await.unwrap_or_default();
return Err(format!("HTTP {}: {}", status, body)); return Err(format!("HTTP {}: {}", status, body));
} }
Ok(body) Ok("ok".to_string())
} }
} }

View File

@@ -530,8 +530,10 @@ impl eframe::App for App {
if let Some(c) = client.as_ref() { if let Some(c) = client.as_ref() {
match c.shutdown_node(&node).await { match c.shutdown_node(&node).await {
Ok(response) => { Ok(response) => {
state.write().unwrap().add_log("✓ 关机命令发送成功"); let mut s = state.write().unwrap();
state.write().unwrap().add_log(&format!("响应: {}", response)); s.add_log("✓ 关机命令发送成功");
s.add_log(&format!("响应: {}", response));
s.is_connected = false;
} }
Err(e) => { Err(e) => {
state.write().unwrap().add_log(&format!("✗ 关机失败: {}", e)); state.write().unwrap().add_log(&format!("✗ 关机失败: {}", e));