You've already forked AstralRinth
forked from didirus/AstralRinth
Fix issues
This commit is contained in:
@@ -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/{} (support@modrinth.com)",
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ pub const CURRENT_FABRIC_FORMAT_VERSION: usize = 0;
|
||||
/// The latest version of the format the fabric model structs deserialize to
|
||||
pub const CURRENT_FORGE_FORMAT_VERSION: usize = 0;
|
||||
|
||||
/// The dummy replace string library names, inheritsFrom, and version names should be replaced with
|
||||
pub const DUMMY_REPLACE_STRING: &str = "${modrinth.gameVersion}";
|
||||
|
||||
/// A data variable entry that depends on the side of the installation
|
||||
#[cfg_attr(feature = "bincode", derive(Encode, Decode))]
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
@@ -93,6 +96,8 @@ pub fn merge_partial_version(
|
||||
partial: PartialVersionInfo,
|
||||
merge: VersionInfo,
|
||||
) -> VersionInfo {
|
||||
let merge_id = merge.id.clone();
|
||||
|
||||
VersionInfo {
|
||||
arguments: if let Some(partial_args) = partial.arguments {
|
||||
if let Some(merge_args) = merge.arguments {
|
||||
@@ -126,12 +131,22 @@ pub fn merge_partial_version(
|
||||
asset_index: merge.asset_index,
|
||||
assets: merge.assets,
|
||||
downloads: merge.downloads,
|
||||
id: partial.id,
|
||||
id: merge.id,
|
||||
java_version: merge.java_version,
|
||||
libraries: partial
|
||||
.libraries
|
||||
.into_iter()
|
||||
.chain(merge.libraries)
|
||||
.map(|x| Library {
|
||||
downloads: x.downloads,
|
||||
extract: x.extract,
|
||||
name: x.name.replace(DUMMY_REPLACE_STRING, &merge_id),
|
||||
url: x.url,
|
||||
natives: x.natives,
|
||||
rules: x.rules,
|
||||
checksums: x.checksums,
|
||||
include_in_classpath: x.include_in_classpath,
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
main_class: if let Some(main_class) = partial.main_class {
|
||||
main_class
|
||||
@@ -163,6 +178,8 @@ pub struct Manifest {
|
||||
pub struct Version {
|
||||
/// The minecraft version ID
|
||||
pub id: String,
|
||||
/// Whether the release is stable or not
|
||||
pub stable: bool,
|
||||
/// A map that contains loader versions for the game version
|
||||
pub loaders: Vec<LoaderVersion>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user