Skip to content

Commit

Permalink
Merge pull request #3 from modrinth/many-fixes
Browse files Browse the repository at this point in the history
Many fixes
  • Loading branch information
Geometrically committed Apr 5, 2023
2 parents b7e2d7f + 9754f2d commit b9de2b4
Show file tree
Hide file tree
Showing 10 changed files with 756 additions and 599 deletions.
1 change: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
RUST_LOG=info,error

BASE_URL=https://modrinth-cdn-staging.nyc3.digitaloceanspaces.com
BASE_FOLDER=gamedata

S3_ACCESS_TOKEN=none
S3_SECRET=none
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.65
FROM rust:1.68.2

COPY ./ ./

Expand Down
2 changes: 1 addition & 1 deletion daedalus/Cargo.toml
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"
Expand Down
52 changes: 43 additions & 9 deletions daedalus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
19 changes: 18 additions & 1 deletion daedalus/src/modded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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>,
}
Expand Down
2 changes: 1 addition & 1 deletion daedalus_client/Cargo.toml
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"

Expand Down
Loading

0 comments on commit b9de2b4

Please sign in to comment.