aboutsummaryrefslogtreecommitdiff
path: root/src/modules/api
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-04-06 01:53:22 -0700
committerFuwn <[email protected]>2023-04-06 01:53:22 -0700
commit9235be2eedc2c4f3a78cb704b0a107f33607e530 (patch)
treefc927ec6d5a58d2e995cf6ff80ae2804a2265531 /src/modules/api
parentdeps(windmark): bump 0.2.5 -> 0.3.1 (diff)
downloadlocus-9235be2eedc2c4f3a78cb704b0a107f33607e530.tar.xz
locus-9235be2eedc2c4f3a78cb704b0a107f33607e530.zip
feat: native async reqwest calls
Diffstat (limited to 'src/modules/api')
-rw-r--r--src/modules/api/sydney.rs51
1 files changed, 27 insertions, 24 deletions
diff --git a/src/modules/api/sydney.rs b/src/modules/api/sydney.rs
index 20f8faa..e66f91d 100644
--- a/src/modules/api/sydney.rs
+++ b/src/modules/api/sydney.rs
@@ -27,34 +27,37 @@ pub fn module(router: &mut windmark::Router) {
"/api/sydney/version",
"Sydney's version",
move |context| {
- let mut content = "0.0.0".to_string();
-
- if let Ok(response) = reqwest::blocking::Client::new()
- .get("https://api.github.com/repos/gemrest/sydney/tags")
- .header(
- "User-Agent",
- format!("{}/{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")),
- )
- .send()
- {
- if let Ok(response_content) = response.json::<Vec<Tags>>() {
- let response_content: Vec<Tags> = response_content;
-
- if let Some(first_tag) = response_content.get(0) {
- content = first_tag.name().clone();
- }
-
- if let Some(just_tag) = content.get(1..) {
- content = just_tag.to_string();
+ async move {
+ let mut content = "0.0.0".to_string();
+
+ if let Ok(response) = reqwest::Client::new()
+ .get("https://api.github.com/repos/gemrest/sydney/tags")
+ .header(
+ "User-Agent",
+ format!("{}/{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")),
+ )
+ .send()
+ .await
+ {
+ if let Ok(response_content) = response.json::<Vec<Tags>>().await {
+ let response_content: Vec<Tags> = response_content;
+
+ if let Some(first_tag) = response_content.get(0) {
+ content = first_tag.name().clone();
+ }
+
+ if let Some(just_tag) = content.get(1..) {
+ content = just_tag.to_string();
+ }
}
}
- }
- crate::route::cache(&context, &content);
+ crate::route::cache(&context, &content);
- windmark::Response::success(content)
- .with_mime("text/plain")
- .clone()
+ windmark::Response::success(content)
+ .with_mime("text/plain")
+ .clone()
+ }
},
);
}