diff --git a/src/auth/tests/accounts.rs b/src/auth/tests/accounts.rs index 6f482de..de9745e 100644 --- a/src/auth/tests/accounts.rs +++ b/src/auth/tests/accounts.rs @@ -25,9 +25,12 @@ fn offline_uuid_has_valid_v3_shape() { } #[test] -fn offline_uuid_deterministic() { - assert_eq!(offline_uuid("Steve"), offline_uuid("Steve")); - assert_eq!(offline_uuid("Alex"), offline_uuid("Alex")); +fn offline_uuid_is_pinned_for_known_names() { + assert_eq!( + offline_uuid("Steve"), + "7e0a3689-ed7c-347c-87cc-3689ed7c47cc" + ); + assert_eq!(offline_uuid("Alex"), "a13d42a3-454f-3e39-a392-42a3454fe392"); } #[test] diff --git a/src/instance/content/provider.rs b/src/instance/content/provider.rs index 563e8af..8fc72ee 100644 --- a/src/instance/content/provider.rs +++ b/src/instance/content/provider.rs @@ -181,7 +181,9 @@ impl ContentProvider for ModrinthProvider { } async fn icon(&self, url: &str) -> Result, crate::net::NetError> { - self.client.get_bytes(url).await + self.client + .get_bytes_limited(url, crate::net::MAX_PROVIDER_ASSET_BYTES) + .await } async fn download_version( @@ -338,7 +340,9 @@ impl ContentProvider for CurseForgeProvider { } async fn icon(&self, url: &str) -> Result, crate::net::NetError> { - self.client.get_bytes(url).await + self.client + .get_bytes_limited(url, crate::net::MAX_PROVIDER_ASSET_BYTES) + .await } async fn download_version( diff --git a/src/net/mod.rs b/src/net/mod.rs index 777b9dc..56a8b7c 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -15,6 +15,8 @@ use serde::de::DeserializeOwned; use std::path::Path; use thiserror::Error; +pub const MAX_PROVIDER_ASSET_BYTES: usize = 16 * 1024 * 1024; + #[derive(Debug, Error)] pub enum NetError { #[error("HTTP request failed: {0}")] diff --git a/src/tui/input.rs b/src/tui/input.rs index 75a8c8b..5c60472 100644 --- a/src/tui/input.rs +++ b/src/tui/input.rs @@ -1176,12 +1176,14 @@ impl App { ) { widgets::content::discovery::spawn_provider_search( query, - widgets::content::discovery::DiscoveryTarget::Content { - instance, - kind, - manifest, - minecraft_dir, - }, + widgets::content::discovery::DiscoveryTarget::Content(Box::new( + widgets::content::discovery::ContentDiscoveryTarget { + instance, + kind, + manifest, + minecraft_dir, + }, + )), meta_dir, request, ); diff --git a/src/tui/widgets/content/discovery.rs b/src/tui/widgets/content/discovery.rs index 870cf6a..688892e 100644 --- a/src/tui/widgets/content/discovery.rs +++ b/src/tui/widgets/content/discovery.rs @@ -80,13 +80,15 @@ pub struct DiscoveryRequest { pub known_projects: std::collections::HashMap, } +pub(crate) struct ContentDiscoveryTarget { + pub instance: InstanceConfig, + pub kind: ContentKind, + pub manifest: Option, + pub minecraft_dir: PathBuf, +} + pub(crate) enum DiscoveryTarget { - Content { - instance: InstanceConfig, - kind: ContentKind, - manifest: Option, - minecraft_dir: PathBuf, - }, + Content(Box), Modpacks, } @@ -100,8 +102,10 @@ async fn search_provider( ) -> Option> { let provider = provider.filter(|_| enabled)?; Some(match target { - DiscoveryTarget::Content { instance, kind, .. } => { - provider.search(*kind, query, instance, offset, limit).await + DiscoveryTarget::Content(content) => { + provider + .search(content.kind, query, &content.instance, offset, limit) + .await } DiscoveryTarget::Modpacks => provider.search_modpacks(query, offset, limit).await, }) @@ -182,20 +186,16 @@ pub(crate) fn spawn_provider_search( returned.insert(stem.clone()); let project_id = project.id.clone(); let installed_path = match &target { - DiscoveryTarget::Content { - manifest, - minecraft_dir, - .. - } => merged + DiscoveryTarget::Content(content) => merged .sources .iter() .filter(|(source_stem, _)| source_stem == &stem) .find_map(|(_, source)| { - manifest.as_ref().and_then(|manifest| { + content.manifest.as_ref().and_then(|manifest| { manifest.resolved_project_path( &source.provider, &source.project_id, - minecraft_dir, + &content.minecraft_dir, ) }) }), @@ -227,10 +227,7 @@ pub(crate) fn spawn_provider_search( return; }; match client - .get_bytes_limited( - &url, - crate::tui::widgets::markdown::MAX_PROJECT_IMAGE_BYTES, - ) + .get_bytes_limited(&url, crate::net::MAX_PROVIDER_ASSET_BYTES) .await { Ok(bytes) if !bytes.is_empty() => { @@ -332,10 +329,7 @@ pub(crate) fn spawn_project_page(request: ProjectPageRequest) { .await .map_err(|error| error.to_string())?; let bytes = client - .get_bytes_limited( - &url, - crate::tui::widgets::markdown::MAX_PROJECT_IMAGE_BYTES, - ) + .get_bytes_limited(&url, crate::net::MAX_PROVIDER_ASSET_BYTES) .await .map_err(|error| error.to_string())?; tokio::task::spawn_blocking(move || { diff --git a/src/tui/widgets/markdown.rs b/src/tui/widgets/markdown.rs index ab82033..4070e5d 100644 --- a/src/tui/widgets/markdown.rs +++ b/src/tui/widgets/markdown.rs @@ -30,7 +30,6 @@ use crate::instance::content::{ }; const MAX_DOCUMENT_WIDTH: u16 = 110; -pub(crate) const MAX_PROJECT_IMAGE_BYTES: usize = 16 * 1024 * 1024; const MAX_PROJECT_IMAGE_DIMENSION: u32 = 8192; const MAX_PROJECT_IMAGE_ALLOCATION: u64 = 64 * 1024 * 1024; diff --git a/tests/live_apis.rs b/tests/live_apis.rs index 10e3fb1..4655954 100644 --- a/tests/live_apis.rs +++ b/tests/live_apis.rs @@ -154,7 +154,10 @@ async fn modrinth_discovery_returns_unique_compatible_mods() { .iter() .find_map(|project| project.icon_url.as_deref()) .expect("expected at least one project icon"); - let icon = client.get_bytes(icon_url).await.unwrap(); + let icon = client + .get_bytes_limited(icon_url, net::MAX_PROVIDER_ASSET_BYTES) + .await + .unwrap(); assert!(image::load_from_memory(&icon).is_ok()); let mut seen = result @@ -183,3 +186,25 @@ async fn modrinth_discovery_returns_unique_compatible_mods() { ); } } + +#[tokio::test] +#[ignore = "hits live CurseForge API"] +async fn curseforge_discovery_returns_compatible_mods() { + let api_key = net::curseforge::api_key().expect("build has no CurseForge API key"); + let result = net::curseforge::search_discovery( + &HttpClient::new(), + api_key, + ContentKind::Mod, + "sodium", + "1.21.1", + ModLoader::Fabric, + 0, + 20, + ) + .await + .unwrap(); + + assert!(!result.projects.is_empty()); + assert!(result.total_hits >= result.projects.len()); + assert!(result.projects.iter().all(|project| !project.id.is_empty())); +}