-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sources): multiple sources + AUR
this would probably need a refactor in the future Resolves #2
- Loading branch information
1 parent
1201a35
commit 8322ada
Showing
8 changed files
with
134 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use reqwest::{ | ||
header::{HeaderMap, HeaderValue, USER_AGENT}, | ||
StatusCode, | ||
}; | ||
|
||
pub fn get_latest(package: String, _: String) -> crate::api::ReleaseFuture { | ||
Box::pin(async move { | ||
let url = format!("https://aur.archlinux.org/rpc/v5/info/{}", package); | ||
let mut headers = HeaderMap::new(); | ||
headers.insert(USER_AGENT, HeaderValue::from_static("nvrs")); | ||
let client = reqwest::Client::new(); | ||
|
||
let result = client.get(url).headers(headers).send().await.unwrap(); | ||
|
||
match result.status() { | ||
StatusCode::OK => (), | ||
status => { | ||
crate::custom_error("GET request didn't return 200", format!("\n{}", status)); | ||
} | ||
} | ||
|
||
let json: serde_json::Value = result.json().await.unwrap(); | ||
let first_result = json.get("results").unwrap().get(0).unwrap(); | ||
|
||
crate::api::Release { | ||
tag_name: first_result | ||
.get("Version") | ||
.unwrap() | ||
.to_string() | ||
.split('-') | ||
.next() | ||
.unwrap_or("") | ||
.to_string(), | ||
html_url: first_result.get("URL").unwrap().to_string(), | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,32 @@ | ||
use serde::Deserialize; | ||
|
||
#[cfg(feature = "aur")] | ||
pub mod aur; | ||
#[cfg(feature = "github")] | ||
pub mod github; | ||
|
||
#[derive(Deserialize)] | ||
pub struct Release { | ||
pub tag_name: String, | ||
pub html_url: String, | ||
} | ||
|
||
pub type ReleaseFuture = std::pin::Pin<Box<dyn std::future::Future<Output = Release> + Send>>; | ||
|
||
pub struct Api { | ||
pub name: &'static str, | ||
pub func: fn(String, String) -> ReleaseFuture, | ||
} | ||
|
||
pub const API_LIST: &[Api] = &[ | ||
#[cfg(feature = "aur")] | ||
Api { | ||
name: "aur", | ||
func: aur::get_latest, | ||
}, | ||
#[cfg(feature = "github")] | ||
Api { | ||
name: "github", | ||
func: github::get_latest, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters