diff --git a/crates/qbz-library/src/database.rs b/crates/qbz-library/src/database.rs index 52d05f33a..903b93876 100644 --- a/crates/qbz-library/src/database.rs +++ b/crates/qbz-library/src/database.rs @@ -3457,6 +3457,34 @@ impl LibraryDatabase { Ok(result) } + /// Get all custom artist images (for bulk lookup) + pub fn get_all_custom_artist_images( + &self, + ) -> Result, LibraryError> { + let mut stmt = self + .conn + .prepare( + "SELECT artist_name, custom_image_path FROM artist_images WHERE custom_image_path IS NOT NULL", + ) + .map_err(|e| LibraryError::Database(format!("Failed to prepare query: {}", e)))?; + + let rows = stmt + .query_map([], |row| { + Ok((row.get::<_, String>(0)?, row.get::<_, String>(1)?)) + }) + .map_err(|e| { + LibraryError::Database(format!("Failed to query custom artist images: {}", e)) + })?; + + let mut map = std::collections::HashMap::new(); + for row in rows { + if let Ok((artist_name, custom_image_path)) = row { + map.insert(artist_name, custom_image_path); + } + } + Ok(map) + } + /// Get all canonical artist names mapping (for bulk lookup) pub fn get_all_canonical_names( &self, diff --git a/src-tauri/src/commands_v2.rs b/src-tauri/src/commands_v2.rs index 56328a424..28f451c37 100644 --- a/src-tauri/src/commands_v2.rs +++ b/src-tauri/src/commands_v2.rs @@ -4337,6 +4337,15 @@ pub async fn v2_library_get_artist_image( db.get_artist_image(&artist_name).map_err(|e| e.to_string()) } +#[tauri::command] +pub async fn v2_library_get_all_custom_artist_images( + state: State<'_, LibraryState>, +) -> Result, String> { + let guard = state.db.lock().await; + let db = guard.as_ref().ok_or("No active session - please log in")?; + db.get_all_custom_artist_images().map_err(|e| e.to_string()) +} + #[tauri::command] pub async fn v2_create_artist_radio( artist_id: u64, diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 10832c50f..fb131dd02 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -904,6 +904,7 @@ pub fn run() { commands_v2::v2_library_set_custom_artist_image, commands_v2::v2_library_remove_custom_artist_image, commands_v2::v2_library_get_artist_image, + commands_v2::v2_library_get_all_custom_artist_images, commands_v2::v2_show_track_notification, commands_v2::v2_subscribe_playlist, commands_v2::v2_cache_track_for_offline,