You've already forked AstralRinth
forked from didirus/AstralRinth
Simplify mod loader manifests, start work on new forge profiles
This commit is contained in:
@@ -1,33 +1,47 @@
|
||||
use crate::{format_url, upload_file_to_bucket, Error};
|
||||
use daedalus::fabric::PartialVersionInfo;
|
||||
use daedalus::download_file;
|
||||
use daedalus::minecraft::Library;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc};
|
||||
use std::time::{Duration, Instant};
|
||||
use daedalus::modded::{LoaderType, LoaderVersion, Manifest, PartialVersionInfo, Version};
|
||||
use futures::lock::Mutex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
pub async fn retrieve_data() -> Result<(), Error> {
|
||||
let mut list = daedalus::fabric::fetch_fabric_versions(None).await?;
|
||||
let mut list = fetch_fabric_versions(None).await?;
|
||||
let old_manifest = daedalus::modded::fetch_manifest(&*format!(
|
||||
"fabric/v{}/manifest.json",
|
||||
daedalus::modded::CURRENT_FABRIC_FORMAT_VERSION,
|
||||
))
|
||||
.await
|
||||
.ok();
|
||||
|
||||
let versions = Arc::new(Mutex::new(if let Some(old_manifest) = old_manifest {
|
||||
old_manifest.game_versions
|
||||
} else {
|
||||
Vec::new()
|
||||
}));
|
||||
|
||||
if let Some(latest) = list.loader.get(0) {
|
||||
let loaders_mutex = Arc::new(Mutex::new(Vec::new()));
|
||||
let loaders_mutex = Arc::new(Mutex::new(HashMap::new()));
|
||||
let visited_artifacts_mutex = Arc::new(Mutex::new(Vec::new()));
|
||||
|
||||
{
|
||||
let mut loaders = loaders_mutex.lock().await;
|
||||
|
||||
loaders.push(latest.version.clone());
|
||||
loaders.insert(LoaderType::Latest, latest.version.clone());
|
||||
|
||||
if !latest.stable {
|
||||
if let Some(stable) = list.loader.iter().find(|x| x.stable) {
|
||||
loaders.push(stable.version.clone());
|
||||
loaders.insert(LoaderType::Stable, stable.version.clone());
|
||||
}
|
||||
}
|
||||
|
||||
list.loader = list
|
||||
.loader
|
||||
.into_iter()
|
||||
.filter(|x| loaders.contains(&x.version))
|
||||
.filter(|x| loaders.values().any(|val| val == &x.version))
|
||||
.collect();
|
||||
}
|
||||
|
||||
@@ -35,105 +49,127 @@ pub async fn retrieve_data() -> Result<(), Error> {
|
||||
|
||||
for game_version in list.game.iter_mut() {
|
||||
let visited_artifacts_mutex = Arc::clone(&visited_artifacts_mutex);
|
||||
let game_version_mutex = Mutex::new(HashMap::new());
|
||||
let loaders_mutex = Arc::clone(&loaders_mutex);
|
||||
|
||||
let versions_mutex = Arc::clone(&versions);
|
||||
version_futures.push(async move {
|
||||
let versions = futures::future::try_join_all(loaders_mutex.lock().await.clone().into_iter().map(
|
||||
|loader| async {
|
||||
let version = daedalus::fabric::fetch_fabric_version(
|
||||
&*game_version.version,
|
||||
&*loader,
|
||||
)
|
||||
.await
|
||||
.expect(&*format!("{}, {}", game_version.version, loader));
|
||||
let loader_version_mutex = Mutex::new(HashMap::new());
|
||||
|
||||
Ok::<(String, PartialVersionInfo), Error>((loader, version))
|
||||
},
|
||||
))
|
||||
.await?;
|
||||
|
||||
futures::future::try_join_all(versions.into_iter().map(
|
||||
|(loader, version)| async {
|
||||
let libs = futures::future::try_join_all(
|
||||
version.libraries.into_iter().map(|mut lib| async {
|
||||
let versions =
|
||||
futures::future::try_join_all(
|
||||
loaders_mutex.lock().await.clone().into_iter().map(
|
||||
|(type_, loader)| async {
|
||||
{
|
||||
let mut visited_assets = visited_artifacts_mutex.lock().await;
|
||||
|
||||
if visited_assets.contains(&lib.name) {
|
||||
lib.url = Some(format_url("maven/"));
|
||||
|
||||
return Ok(lib);
|
||||
} else {
|
||||
visited_assets.push(lib.name.clone())
|
||||
if versions_mutex.lock().await.iter().any(|x| {
|
||||
x.id == game_version.version
|
||||
&& x.loaders
|
||||
.get(&type_)
|
||||
.map(|x| x.id == loader)
|
||||
.unwrap_or(false)
|
||||
}) {
|
||||
return Ok(None);
|
||||
}
|
||||
}
|
||||
|
||||
let artifact_path =
|
||||
daedalus::get_path_from_artifact(&*lib.name)?;
|
||||
let version =
|
||||
fetch_fabric_version(&*game_version.version, &*loader).await?;
|
||||
|
||||
let artifact = daedalus::download_file(
|
||||
&*format!(
|
||||
"{}{}",
|
||||
lib.url.unwrap_or_else(|| {
|
||||
"https://maven.fabricmc.net/".to_string()
|
||||
}),
|
||||
artifact_path
|
||||
),
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
Ok::<Option<(LoaderType, String, PartialVersionInfo)>, Error>(Some(
|
||||
(type_, loader, version),
|
||||
))
|
||||
},
|
||||
),
|
||||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
.flatten();
|
||||
|
||||
lib.url = Some(format_url("maven/"));
|
||||
futures::future::try_join_all(versions.map(|(type_, loader, version)| async {
|
||||
let libs = futures::future::try_join_all(version.libraries.into_iter().map(
|
||||
|mut lib| async {
|
||||
{
|
||||
let mut visited_assets = visited_artifacts_mutex.lock().await;
|
||||
|
||||
upload_file_to_bucket(
|
||||
format!("{}/{}", "maven", artifact_path),
|
||||
artifact.to_vec(),
|
||||
Some("application/java-archive".to_string()),
|
||||
)
|
||||
.await?;
|
||||
if visited_assets.contains(&lib.name) {
|
||||
lib.url = Some(format_url("maven/"));
|
||||
|
||||
Ok::<Library, Error>(lib)
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
return Ok(lib);
|
||||
} else {
|
||||
visited_assets.push(lib.name.clone())
|
||||
}
|
||||
}
|
||||
|
||||
let version_path = format!(
|
||||
"fabric/v{}/versions/{}-{}.json",
|
||||
daedalus::fabric::CURRENT_FORMAT_VERSION,
|
||||
version.inherits_from,
|
||||
loader
|
||||
let artifact_path = daedalus::get_path_from_artifact(&*lib.name)?;
|
||||
|
||||
let artifact = daedalus::download_file(
|
||||
&*format!(
|
||||
"{}{}",
|
||||
lib.url.unwrap_or_else(|| {
|
||||
"https://maven.fabricmc.net/".to_string()
|
||||
}),
|
||||
artifact_path
|
||||
),
|
||||
None,
|
||||
)
|
||||
.await?;
|
||||
|
||||
lib.url = Some(format_url("maven/"));
|
||||
|
||||
upload_file_to_bucket(
|
||||
format!("{}/{}", "maven", artifact_path),
|
||||
artifact.to_vec(),
|
||||
Some("application/java-archive".to_string()),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok::<Library, Error>(lib)
|
||||
},
|
||||
))
|
||||
.await?;
|
||||
|
||||
let version_path = format!(
|
||||
"fabric/v{}/versions/{}-{}.json",
|
||||
daedalus::modded::CURRENT_FABRIC_FORMAT_VERSION,
|
||||
version.inherits_from,
|
||||
loader
|
||||
);
|
||||
|
||||
upload_file_to_bucket(
|
||||
version_path.clone(),
|
||||
serde_json::to_vec(&PartialVersionInfo {
|
||||
arguments: version.arguments,
|
||||
id: version.id,
|
||||
main_class: version.main_class,
|
||||
release_time: version.release_time,
|
||||
time: version.time,
|
||||
type_: version.type_,
|
||||
inherits_from: version.inherits_from,
|
||||
libraries: libs,
|
||||
})?,
|
||||
Some("application/json".to_string()),
|
||||
)
|
||||
.await?;
|
||||
|
||||
{
|
||||
let mut loader_version_map = loader_version_mutex.lock().await;
|
||||
loader_version_map.insert(
|
||||
type_,
|
||||
LoaderVersion {
|
||||
id: loader,
|
||||
url: format_url(&*version_path),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
upload_file_to_bucket(
|
||||
version_path.clone(),
|
||||
serde_json::to_vec(&PartialVersionInfo {
|
||||
arguments: version.arguments,
|
||||
id: version.id,
|
||||
main_class: version.main_class,
|
||||
release_time: version.release_time,
|
||||
time: version.time,
|
||||
type_: version.type_,
|
||||
inherits_from: version.inherits_from,
|
||||
libraries: libs,
|
||||
})?,
|
||||
Some("application/json".to_string()),
|
||||
)
|
||||
.await?;
|
||||
|
||||
{
|
||||
let mut game_version_map = game_version_mutex.lock().await;
|
||||
game_version_map.insert(loader, format_url(&*version_path));
|
||||
}
|
||||
|
||||
Ok::<(), Error>(())
|
||||
},
|
||||
))
|
||||
Ok::<(), Error>(())
|
||||
}))
|
||||
.await?;
|
||||
|
||||
game_version.urls = Some(
|
||||
game_version_mutex.lock().await
|
||||
.clone(),
|
||||
);
|
||||
let mut versions = versions_mutex.lock().await;
|
||||
versions.push(Version {
|
||||
id: game_version.version.clone(),
|
||||
loaders: loader_version_mutex.into_inner(),
|
||||
});
|
||||
|
||||
Ok::<(), Error>(())
|
||||
});
|
||||
@@ -156,15 +192,80 @@ pub async fn retrieve_data() -> Result<(), Error> {
|
||||
}
|
||||
}
|
||||
|
||||
upload_file_to_bucket(
|
||||
format!(
|
||||
"fabric/v{}/manifest.json",
|
||||
daedalus::fabric::CURRENT_FORMAT_VERSION,
|
||||
),
|
||||
serde_json::to_vec(&list)?,
|
||||
Some("application/json".to_string()),
|
||||
)
|
||||
.await?;
|
||||
if let Ok(versions) = Arc::try_unwrap(versions) {
|
||||
upload_file_to_bucket(
|
||||
format!(
|
||||
"fabric/v{}/manifest.json",
|
||||
daedalus::modded::CURRENT_FABRIC_FORMAT_VERSION,
|
||||
),
|
||||
serde_json::to_vec(&Manifest {
|
||||
game_versions: versions.into_inner(),
|
||||
})?,
|
||||
Some("application/json".to_string()),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
const FABRIC_META_URL: &str = "https://meta.fabricmc.net/v2";
|
||||
|
||||
async fn fetch_fabric_version(
|
||||
version_number: &str,
|
||||
loader_version: &str,
|
||||
) -> Result<PartialVersionInfo, Error> {
|
||||
Ok(serde_json::from_slice(
|
||||
&download_file(
|
||||
&*format!(
|
||||
"{}/versions/loader/{}/{}/profile/json",
|
||||
FABRIC_META_URL, version_number, loader_version
|
||||
),
|
||||
None,
|
||||
)
|
||||
.await?,
|
||||
)?)
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
/// Versions of fabric components
|
||||
struct FabricVersions {
|
||||
/// Versions of Minecraft that fabric supports
|
||||
pub game: Vec<FabricGameVersion>,
|
||||
/// Available versions of the fabric loader
|
||||
pub loader: Vec<FabricLoaderVersion>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
/// A version of Minecraft that fabric supports
|
||||
struct FabricGameVersion {
|
||||
/// The version number of the game
|
||||
pub version: String,
|
||||
/// Whether the Minecraft version is stable or not
|
||||
pub stable: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
/// A version of the fabric loader
|
||||
struct FabricLoaderVersion {
|
||||
/// The separator to get the build number
|
||||
pub separator: String,
|
||||
/// The build number
|
||||
pub build: u32,
|
||||
/// The maven artifact
|
||||
pub maven: String,
|
||||
/// The version number of the fabric loader
|
||||
pub version: String,
|
||||
/// Whether the loader is stable or not
|
||||
pub stable: bool,
|
||||
}
|
||||
/// Fetches the list of fabric versions
|
||||
async fn fetch_fabric_versions(url: Option<&str>) -> Result<FabricVersions, Error> {
|
||||
Ok(serde_json::from_slice(
|
||||
&download_file(
|
||||
url.unwrap_or(&*format!("{}/versions", FABRIC_META_URL)),
|
||||
None,
|
||||
)
|
||||
.await?,
|
||||
)?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user