refactor: upgrade crates and restructure project

This commit is contained in:
objz committed 2026-04-18 16:59:27 +02:00
1 parent ea093c044f
commit 47dad69321
80 files changed
+6094 -6125

No files matched your search

+6 -96
View File
@@ -43,27 +43,7 @@ pub struct FabricLibrary {
pub async fn fetch_fabric_game_versions(client: &HttpClient) -> Result<Vec<GameVersion>, NetError> {
let url = format!("{}/versions/game", FABRIC_META_BASE);
let response = match client.inner().get(&url).send().await {
Ok(r) => r,
Err(e) => {
tracing::error!("Fabric game versions GET {} failed: {}", url, e);
return Err(NetError::Http(e));
}
};
if !response.status().is_success() {
let status = response.status().as_u16();
tracing::error!("HTTP {} for {}", status, url);
return Err(NetError::StatusError { status, url });
}
let versions: Vec<FabricGameVersion> = match response.json().await {
Ok(v) => v,
Err(e) => {
tracing::error!("Failed to parse Fabric game versions: {}", e);
return Err(NetError::Http(e));
}
};
let versions: Vec<FabricGameVersion> = client.get_json(&url).await?;
Ok(versions
.into_iter()
@@ -79,33 +59,7 @@ pub async fn fetch_fabric_versions(
game_version: &str,
) -> Result<Vec<FabricLoaderVersion>, NetError> {
let url = format!("{}/versions/loader/{}", FABRIC_META_BASE, game_version);
let response = match client.inner().get(&url).send().await {
Ok(r) => r,
Err(e) => {
tracing::error!("Fabric meta GET {} failed: {}", url, e);
return Err(NetError::Http(e));
}
};
if !response.status().is_success() {
let status = response.status().as_u16();
tracing::error!("Fabric meta HTTP {} for {}", status, url);
return Err(NetError::StatusError {
status,
url: url.clone(),
});
}
let versions: Vec<FabricLoaderVersion> = match response.json().await {
Ok(v) => v,
Err(e) => {
tracing::error!("Failed to parse Fabric loader versions: {}", e);
return Err(NetError::Http(e));
}
};
Ok(versions)
client.get_json(&url).await
}
pub async fn fetch_fabric_profile(
@@ -117,33 +71,7 @@ pub async fn fetch_fabric_profile(
"{}/versions/loader/{}/{}/profile/json",
FABRIC_META_BASE, game_version, loader_version
);
let response = match client.inner().get(&url).send().await {
Ok(r) => r,
Err(e) => {
tracing::error!("Fabric profile GET {} failed: {}", url, e);
return Err(NetError::Http(e));
}
};
if !response.status().is_success() {
let status = response.status().as_u16();
tracing::error!("Fabric profile HTTP {} for {}", status, url);
return Err(NetError::StatusError {
status,
url: url.clone(),
});
}
let profile: FabricProfile = match response.json().await {
Ok(p) => p,
Err(e) => {
tracing::error!("Failed to parse Fabric profile: {}", e);
return Err(NetError::Http(e));
}
};
Ok(profile)
client.get_json(&url).await
}
pub async fn download_fabric_libraries(
@@ -157,7 +85,6 @@ pub async fn download_fabric_libraries(
let maven_path = match crate::net::maven_coord_to_path(&lib.name) {
Some(p) => p,
None => {
tracing::error!("Invalid Maven coordinate in Fabric profile: {}", lib.name);
return Err(NetError::Parse(format!(
"Invalid Maven coordinate: {}",
lib.name
@@ -178,13 +105,7 @@ pub async fn download_fabric_libraries(
set_sub_action(&lib.name);
tracing::info!("Downloading Fabric library: {}", lib.name);
match download_file(client, &download_url, &dest, |_, _| {}).await {
Ok(()) => {}
Err(e) => {
tracing::error!("Failed to download Fabric library {}: {}", lib.name, e);
return Err(e);
}
}
download_file(client, &download_url, &dest, |_, _| {}).await?;
}
Ok(())
@@ -196,6 +117,7 @@ mod tests {
use crate::net::HttpClient;
#[tokio::test]
#[ignore = "hits live Fabric API"]
async fn test_fetch_versions() {
let client = HttpClient::new();
match fetch_fabric_versions(&client, "1.20.1").await {
@@ -214,6 +136,7 @@ mod tests {
}
#[tokio::test]
#[ignore = "hits live Fabric API"]
async fn test_fetch_game_versions() {
let client = HttpClient::new();
match fetch_fabric_game_versions(&client).await {
@@ -225,17 +148,4 @@ mod tests {
}
}
#[test]
fn test_maven_coord_to_path() {
assert_eq!(
crate::net::maven_coord_to_path("net.fabricmc:fabric-loader:0.16.0"),
Some("net/fabricmc/fabric-loader/0.16.0/fabric-loader-0.16.0.jar".to_string())
);
assert_eq!(
crate::net::maven_coord_to_path("org.ow2.asm:asm:9.6"),
Some("org/ow2/asm/asm/9.6/asm-9.6.jar".to_string())
);
assert_eq!(crate::net::maven_coord_to_path("invalid"), None);
assert_eq!(crate::net::maven_coord_to_path("only:two"), None);
}
}