Skip to content

Commit 596af84

Browse files
committed
updater fix
1 parent 6cce72a commit 596af84

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "voxelproxy"
3-
version = "3.0.0"
3+
version = "3.0.1"
44
edition = "2021"
55

66
[dependencies]

src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ __ __ _ ____
7070
Err(e) => {
7171
println!("При проверки обновлений произошла ошибка: {}", e);
7272
println!("Проверьте соединение к интернету");
73-
loop {
74-
let _: String = dialoguer::Input::new().interact_text().unwrap();
75-
}
7673
}
7774
}
7875
}

src/updater.rs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,44 @@ pub async fn has_update(current_version: &str) -> anyhow::Result<Option<NewVersi
1313
let client = Client::new();
1414

1515
let mut headers = HeaderMap::new();
16-
headers.append("User-Agent", HeaderValue::from_str("VP Updater").unwrap());
17-
headers.append(
16+
headers.insert("User-Agent", HeaderValue::from_static("VP Updater"));
17+
headers.insert(
1818
"Accept",
19-
HeaderValue::from_str("application/vnd.github+json").unwrap(),
19+
HeaderValue::from_static("application/vnd.github+json"),
2020
);
21-
headers.append(
21+
headers.insert(
2222
"X-GitHub-Api-Version",
23-
HeaderValue::from_str("2022-11-28").unwrap(),
23+
HeaderValue::from_static("2022-11-28"),
2424
);
2525

26-
let response: Value = client
26+
let response = client
2727
.get("https://api.github.com/repos/kauri-off/voxelproxy/releases/latest")
2828
.headers(headers)
2929
.send()
3030
.await?
31-
.json()
32-
.await?;
33-
34-
if response["tag_name"].as_str().unwrap_or("") != current_version {
35-
let tag = response["tag_name"].as_str().unwrap_or("").to_string();
36-
let link = response["assets"][0]["browser_download_url"]
37-
.as_str()
38-
.unwrap_or("Error")
39-
.to_string();
40-
return Ok(Some(NewVersion { tag, link }));
31+
.error_for_status()?; // Проверка на 4xx/5xx статус
32+
33+
let json: Value = response.json().await?;
34+
35+
let tag = json
36+
.get("tag_name")
37+
.and_then(Value::as_str)
38+
.ok_or_else(|| anyhow::anyhow!("Missing or invalid 'tag_name' field"))?;
39+
40+
if tag == current_version {
41+
return Ok(None);
4142
}
4243

43-
Ok(None)
44+
let asset_url = json
45+
.get("assets")
46+
.and_then(Value::as_array)
47+
.and_then(|assets| assets.first())
48+
.and_then(|asset| asset.get("browser_download_url"))
49+
.and_then(Value::as_str)
50+
.ok_or_else(|| anyhow::anyhow!("Missing or invalid asset download URL"))?;
51+
52+
Ok(Some(NewVersion {
53+
tag: tag.to_string(),
54+
link: asset_url.to_string(),
55+
}))
4456
}

0 commit comments

Comments
 (0)