-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7e2d7f
commit 79ceb56
Showing
9 changed files
with
741 additions
and
625 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM rust:1.65 | ||
FROM rust:1.68.2 | ||
|
||
COPY ./ ./ | ||
|
||
|
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,6 +1,6 @@ | ||
[package] | ||
name = "daedalus" | ||
version = "0.1.17" | ||
version = "0.1.18" | ||
authors = ["Jai A <[email protected]>"] | ||
edition = "2018" | ||
license = "MIT" | ||
|
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 |
---|---|---|
|
@@ -46,22 +46,34 @@ pub fn get_path_from_artifact(artifact: &str) -> Result<String, Error> { | |
let name_items = artifact.split(':').collect::<Vec<&str>>(); | ||
|
||
let package = name_items.first().ok_or_else(|| { | ||
Error::ParseError(format!("Unable to find package for library {}", &artifact)) | ||
Error::ParseError(format!( | ||
"Unable to find package for library {}", | ||
&artifact | ||
)) | ||
})?; | ||
let name = name_items.get(1).ok_or_else(|| { | ||
Error::ParseError(format!("Unable to find name for library {}", &artifact)) | ||
Error::ParseError(format!( | ||
"Unable to find name for library {}", | ||
&artifact | ||
)) | ||
})?; | ||
|
||
if name_items.len() == 3 { | ||
let version_ext = name_items | ||
.get(2) | ||
.ok_or_else(|| { | ||
Error::ParseError(format!("Unable to find version for library {}", &artifact)) | ||
Error::ParseError(format!( | ||
"Unable to find version for library {}", | ||
&artifact | ||
)) | ||
})? | ||
.split('@') | ||
.collect::<Vec<&str>>(); | ||
let version = version_ext.first().ok_or_else(|| { | ||
Error::ParseError(format!("Unable to find version for library {}", &artifact)) | ||
Error::ParseError(format!( | ||
"Unable to find version for library {}", | ||
&artifact | ||
)) | ||
})?; | ||
let ext = version_ext.get(1); | ||
|
||
|
@@ -76,18 +88,27 @@ pub fn get_path_from_artifact(artifact: &str) -> Result<String, Error> { | |
)) | ||
} else { | ||
let version = name_items.get(2).ok_or_else(|| { | ||
Error::ParseError(format!("Unable to find version for library {}", &artifact)) | ||
Error::ParseError(format!( | ||
"Unable to find version for library {}", | ||
&artifact | ||
)) | ||
})?; | ||
|
||
let data_ext = name_items | ||
.get(3) | ||
.ok_or_else(|| { | ||
Error::ParseError(format!("Unable to find data for library {}", &artifact)) | ||
Error::ParseError(format!( | ||
"Unable to find data for library {}", | ||
&artifact | ||
)) | ||
})? | ||
.split('@') | ||
.collect::<Vec<&str>>(); | ||
let data = data_ext.first().ok_or_else(|| { | ||
Error::ParseError(format!("Unable to find data for library {}", &artifact)) | ||
Error::ParseError(format!( | ||
"Unable to find data for library {}", | ||
&artifact | ||
)) | ||
})?; | ||
let ext = data_ext.get(1); | ||
|
||
|
@@ -126,10 +147,21 @@ pub async fn download_file_mirrors( | |
} | ||
|
||
/// Downloads a file with retry and checksum functionality | ||
pub async fn download_file(url: &str, sha1: Option<&str>) -> Result<bytes::Bytes, Error> { | ||
pub async fn download_file( | ||
url: &str, | ||
sha1: Option<&str>, | ||
) -> Result<bytes::Bytes, Error> { | ||
let mut headers = reqwest::header::HeaderMap::new(); | ||
if let Ok(header) = reqwest::header::HeaderValue::from_str(&format!( | ||
"modrinth/daedalus/{} ([email protected])", | ||
env!("CARGO_PKG_VERSION") | ||
)) { | ||
headers.insert(reqwest::header::USER_AGENT, header); | ||
} | ||
let client = reqwest::Client::builder() | ||
.tcp_keepalive(Some(std::time::Duration::from_secs(10))) | ||
.timeout(std::time::Duration::from_secs(15)) | ||
.default_headers(headers) | ||
.build() | ||
.map_err(|err| Error::FetchError { | ||
inner: err, | ||
|
@@ -183,7 +215,9 @@ pub async fn download_file(url: &str, sha1: Option<&str>) -> Result<bytes::Bytes | |
|
||
/// Computes a checksum of the input bytes | ||
pub async fn get_hash(bytes: bytes::Bytes) -> Result<String, Error> { | ||
let hash = tokio::task::spawn_blocking(|| sha1::Sha1::from(bytes).hexdigest()).await?; | ||
let hash = | ||
tokio::task::spawn_blocking(|| sha1::Sha1::from(bytes).hexdigest()) | ||
.await?; | ||
|
||
Ok(hash) | ||
} |
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,6 +1,6 @@ | ||
[package] | ||
name = "daedalus_client" | ||
version = "0.1.17" | ||
version = "0.1.18" | ||
authors = ["Jai A <[email protected]>"] | ||
edition = "2018" | ||
|
||
|
Oops, something went wrong.