diff --git a/src/main.rs b/src/main.rs index 59d731e4..c30bcbdb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -124,19 +124,19 @@ impl App { } else { None }; - let now_version = configs::CONFIG.read().unwrap().app.get_version().unwrap(); + let now_version = &format!("v{}",configs::CONFIG.read().unwrap().app.get_version().unwrap()); if latest_version_data.is_some() && now_version != latest_version_data .as_ref() - .unwrap_or(&now_version.to_string()) + .unwrap_or(now_version) { write_color_buffer( &BufferWriter::stdout(ColorChoice::Always), None, &format!( "There is a new version of Hayabusa: {}", - latest_version_data.unwrap() + latest_version_data.unwrap().replace('\"',"") ), true, ) diff --git a/src/options/update.rs b/src/options/update.rs index 61d19180..97d3fee5 100644 --- a/src/options/update.rs +++ b/src/options/update.rs @@ -1,3 +1,4 @@ +use serde_json::Value; use crate::detections::message::AlertMessage; use crate::detections::utils::write_color_buffer; use crate::filter; @@ -21,15 +22,19 @@ pub struct Update {} impl Update { /// get latest hayabusa version number. pub fn get_latest_hayabusa_version() -> Result, Box> { - let res = reqwest::blocking::get( + let res = reqwest::blocking::Client::new().get( "https://api.github.com/repos/Yamato-Security/hayabusa/releases/latest", - )? - .json::>()?; - if let Some(o) = res.get("tag_name") { - Ok(Some(o.to_owned())) - } else { + ).header("User-Agent", "HayabusaUpdateChecker") + .header("Accept", "application/vnd.github.v3+json").send()?; + let text = res.text()?; + let json_res:Value = serde_json::from_str(&text)?; + + if json_res["tag_name"].is_null() { Ok(None) + } else { + Ok(Some(json_res["tag_name"].to_string())) } + } /// update rules(hayabusa-rules subrepository)