From 72c2f42c1648e2e8b9dba9f7db9d9763c87adb46 Mon Sep 17 00:00:00 2001 From: Pauline Date: Sun, 14 Jul 2024 21:42:03 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20chore:=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/desktop/src-tauri/src/api/commands.rs | 17 +++++++---- crates/core/src/api/metadata.rs | 35 ++++------------------ crates/core/src/game/metadata.rs | 30 +++++++++++++++---- crates/core/src/store/metadata.rs | 25 ++++++++++++---- 4 files changed, 59 insertions(+), 48 deletions(-) diff --git a/apps/desktop/src-tauri/src/api/commands.rs b/apps/desktop/src-tauri/src/api/commands.rs index 60a37b4c..f9a9780e 100644 --- a/apps/desktop/src-tauri/src/api/commands.rs +++ b/apps/desktop/src-tauri/src/api/commands.rs @@ -174,29 +174,34 @@ pub fn get_program_info() -> ProgramInfo { #[specta::specta] #[tauri::command] pub async fn get_users() -> Result, String> { - minecraft::users().await.map_err(|err| err.into()) + minecraft::users().await.map_err(|err| err.into()) } #[specta::specta] #[tauri::command] pub async fn get_user(uuid: Uuid) -> Result { - minecraft::get_user(uuid).await.map_err(|err| err.into()) + minecraft::get_user(uuid).await.map_err(|err| err.into()) } #[specta::specta] #[tauri::command] pub async fn begin_msa() -> Result { - minecraft::begin().await.map_err(|err| err.into()) + minecraft::begin().await.map_err(|err| err.into()) } #[specta::specta] #[tauri::command] -pub async fn finish_msa(code: String, login: MinecraftLogin) -> Result { - minecraft::finish(code.as_str(), login).await.map_err(|err| err.into()) +pub async fn finish_msa( + code: String, + login: MinecraftLogin, +) -> Result { + minecraft::finish(code.as_str(), login) + .await + .map_err(|err| err.into()) } #[specta::specta] #[tauri::command] pub async fn remove_user(uuid: Uuid) -> Result<(), String> { - minecraft::remove_user(uuid).await.map_err(|err| err.into()) + minecraft::remove_user(uuid).await.map_err(|err| err.into()) } diff --git a/crates/core/src/api/metadata.rs b/crates/core/src/api/metadata.rs index afa434ad..8e2f50bd 100644 --- a/crates/core/src/api/metadata.rs +++ b/crates/core/src/api/metadata.rs @@ -8,12 +8,7 @@ pub use interpulse::api::modded::Manifest; #[tracing::instrument] pub async fn get_minecraft_versions() -> crate::Result { let state = State::get().await?; - let meta = state - .metadata - .read() - .await - .minecraft - .clone(); + let meta = state.metadata.read().await.minecraft.clone(); Ok(meta) } @@ -22,12 +17,7 @@ pub async fn get_minecraft_versions() -> crate::Result { #[tracing::instrument] pub async fn get_fabric_versions() -> crate::Result { let state = State::get().await?; - let meta = state - .metadata - .read() - .await - .fabric - .clone(); + let meta = state.metadata.read().await.fabric.clone(); Ok(meta) } @@ -36,12 +26,7 @@ pub async fn get_fabric_versions() -> crate::Result { #[tracing::instrument] pub async fn get_quilt_versions() -> crate::Result { let state = State::get().await?; - let meta = state - .metadata - .read() - .await - .quilt - .clone(); + let meta = state.metadata.read().await.quilt.clone(); Ok(meta) } @@ -50,12 +35,7 @@ pub async fn get_quilt_versions() -> crate::Result { #[tracing::instrument] pub async fn get_forge_versions() -> crate::Result { let state = State::get().await?; - let meta = state - .metadata - .read() - .await - .forge - .clone(); + let meta = state.metadata.read().await.forge.clone(); Ok(meta) } @@ -64,12 +44,7 @@ pub async fn get_forge_versions() -> crate::Result { #[tracing::instrument] pub async fn get_neoforge_versions() -> crate::Result { let state = State::get().await?; - let meta = state - .metadata - .read() - .await - .neoforge - .clone(); + let meta = state.metadata.read().await.neoforge.clone(); Ok(meta) } diff --git a/crates/core/src/game/metadata.rs b/crates/core/src/game/metadata.rs index 9e33eafe..492aa578 100644 --- a/crates/core/src/game/metadata.rs +++ b/crates/core/src/game/metadata.rs @@ -82,7 +82,7 @@ pub async fn download_version_info( info = ip::api::modded::merge_partial_version(partial, info); } - info.id = version_id.clone(); + info.id.clone_from(&version_id); write(&path, &serde_json::to_vec(&info)?, &st.io_semaphore).await?; Ok(info) @@ -96,11 +96,19 @@ pub async fn download_version_info( Ok(result) } -pub async fn fetch_version_info(version: &ip::api::minecraft::Version, semaphore: &FetchSemaphore) -> crate::Result { - Ok(serde_json::from_slice(&fetch(&version.url, Some(&version.sha1), semaphore).await?)?) +pub async fn fetch_version_info( + version: &ip::api::minecraft::Version, + semaphore: &FetchSemaphore, +) -> crate::Result { + Ok(serde_json::from_slice( + &fetch(&version.url, Some(&version.sha1), semaphore).await?, + )?) } -pub async fn fetch_partial_version(url: &str, semaphore: &FetchSemaphore) -> crate::Result { +pub async fn fetch_partial_version( + url: &str, + semaphore: &FetchSemaphore, +) -> crate::Result { Ok(serde_json::from_slice(&fetch(url, None, semaphore).await?)?) } @@ -139,8 +147,18 @@ pub async fn download_assets_index( Ok(result) } -pub async fn fetch_assets_index(version: &ip::api::minecraft::VersionInfo, semaphore: &FetchSemaphore) -> crate::Result { - Ok(serde_json::from_slice(&fetch(&version.asset_index.url, Some(&version.asset_index.sha1), semaphore).await?)?) +pub async fn fetch_assets_index( + version: &ip::api::minecraft::VersionInfo, + semaphore: &FetchSemaphore, +) -> crate::Result { + Ok(serde_json::from_slice( + &fetch( + &version.asset_index.url, + Some(&version.asset_index.sha1), + semaphore, + ) + .await?, + )?) } #[tracing::instrument(skip(st, index))] diff --git a/crates/core/src/store/metadata.rs b/crates/core/src/store/metadata.rs index 6ecf3074..fb20d234 100644 --- a/crates/core/src/store/metadata.rs +++ b/crates/core/src/store/metadata.rs @@ -50,15 +50,15 @@ impl Metadata { }, async { let url = Self::get_manifest("quilt", interpulse::api::modded::CURRENT_QUILT_FORMAT_VERSION); - fetch_modded_manifest(&url, &semaphore).await + fetch_modded_manifest(&url, semaphore).await }, async { let url = Self::get_manifest("neo", interpulse::api::modded::CURRENT_NEOFORGE_FORMAT_VERSION); - fetch_modded_manifest(&url, &semaphore).await + fetch_modded_manifest(&url, semaphore).await }, async { let url = Self::get_manifest("forge", interpulse::api::modded::CURRENT_FORGE_FORMAT_VERSION); - fetch_modded_manifest(&url, &semaphore).await + fetch_modded_manifest(&url, semaphore).await }, }?; @@ -165,10 +165,23 @@ impl Metadata { } } -async fn fetch_version_manifest(url: Option<&str>, semaphore: &FetchSemaphore) -> crate::Result { - Ok(serde_json::from_slice(&fetch(url.unwrap_or(interpulse::api::minecraft::VERSION_MANIFEST_URL), None, semaphore).await?)?) +async fn fetch_version_manifest( + url: Option<&str>, + semaphore: &FetchSemaphore, +) -> crate::Result { + Ok(serde_json::from_slice( + &fetch( + url.unwrap_or(interpulse::api::minecraft::VERSION_MANIFEST_URL), + None, + semaphore, + ) + .await?, + )?) } -async fn fetch_modded_manifest(url: &str, semaphore: &FetchSemaphore) -> crate::Result { +async fn fetch_modded_manifest( + url: &str, + semaphore: &FetchSemaphore, +) -> crate::Result { Ok(serde_json::from_slice(&fetch(url, None, semaphore).await?)?) }