-
-
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.
Create
NodeURLs
struct for URL related things, move some used code …
…to struct functions
- Loading branch information
Showing
5 changed files
with
86 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
mod lts; | ||
mod release; | ||
mod urls; | ||
|
||
pub use lts::NodeLTS as LTS; | ||
pub use release::NodeRelease as Release; | ||
pub use urls::NodeURLs as URLs; |
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,43 @@ | ||
use anyhow::Context; | ||
|
||
use crate::types; | ||
|
||
#[derive(Debug)] | ||
pub struct NodeURLs { | ||
pub home: &'static str, | ||
pub github: &'static str, | ||
} | ||
|
||
impl NodeURLs { | ||
pub async fn fetch_releases(&self) -> anyhow::Result<Vec<types::node::Release>> { | ||
let response = reqwest::get(self.get_releases_index()).await?; | ||
|
||
if !response.status().is_success() { | ||
anyhow::bail!("Failed to fetch releases: {}", response.status()); | ||
} | ||
|
||
let releases_json = response | ||
.json() | ||
.await | ||
.context("Failed to parse releases JSON")?; | ||
|
||
Ok(releases_json) | ||
} | ||
|
||
pub fn get_releases_index(&self) -> String { | ||
format!("{}/dist/index.json", self.home) | ||
} | ||
|
||
pub fn get_distribution_path(&self) -> String { | ||
format!("{}/dist", self.home) | ||
} | ||
} | ||
|
||
impl Default for NodeURLs { | ||
fn default() -> Self { | ||
Self { | ||
home: "https://nodejs.org", | ||
github: "https://github.com/nodejs/node", | ||
} | ||
} | ||
} |