feat(backend): add bulk queue and bulk favorites commands
- v2_bulk_add_to_queue: add multiple tracks to end of queue - v2_bulk_add_to_queue_next: add multiple tracks as play next (reversed to preserve selection order) - v2_bulk_add_favorites: add multiple tracks to favorites via API then update local cache atomically (lock not held across await points) - v2_add_tracks_to_playlist and v2_remove_tracks_from_playlist already accept Vec<u64> — no changes needed for playlist bulk actions
This commit is contained in:
2 files changed
+79
No files matched your search
@@ -5023,6 +5023,45 @@ pub async fn v2_add_to_queue_next(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Add multiple tracks to end of queue (V2 - bulk)
|
||||
#[tauri::command]
|
||||
pub async fn v2_bulk_add_to_queue(
|
||||
tracks: Vec<V2QueueTrack>,
|
||||
bridge: State<'_, CoreBridgeState>,
|
||||
runtime: State<'_, RuntimeManagerState>,
|
||||
) -> Result<(), RuntimeError> {
|
||||
runtime
|
||||
.manager()
|
||||
.check_requirements(CommandRequirement::RequiresUserSession)
|
||||
.await?;
|
||||
log::info!("[V2] bulk_add_to_queue: {} tracks", tracks.len());
|
||||
let bridge = bridge.get().await;
|
||||
for track in tracks {
|
||||
bridge.add_track(track.into()).await;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Add multiple tracks as play next (V2 - bulk, reversed to preserve order)
|
||||
#[tauri::command]
|
||||
pub async fn v2_bulk_add_to_queue_next(
|
||||
tracks: Vec<V2QueueTrack>,
|
||||
bridge: State<'_, CoreBridgeState>,
|
||||
runtime: State<'_, RuntimeManagerState>,
|
||||
) -> Result<(), RuntimeError> {
|
||||
runtime
|
||||
.manager()
|
||||
.check_requirements(CommandRequirement::RequiresUserSession)
|
||||
.await?;
|
||||
log::info!("[V2] bulk_add_to_queue_next: {} tracks", tracks.len());
|
||||
let bridge = bridge.get().await;
|
||||
// Reverse so the first track in the selection ends up as "next"
|
||||
for track in tracks.into_iter().rev() {
|
||||
bridge.add_track_next(track.into()).await;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set the entire queue and start playing from index (V2 - uses CoreBridge)
|
||||
#[tauri::command]
|
||||
pub async fn v2_set_queue(
|
||||
@@ -8364,6 +8403,43 @@ pub async fn v2_uncache_favorite_track(
|
||||
.map_err(|e| RuntimeError::Internal(e))
|
||||
}
|
||||
|
||||
/// Bulk add tracks to favorites (V2) — adds via API then updates local cache
|
||||
#[tauri::command]
|
||||
#[allow(non_snake_case)]
|
||||
pub async fn v2_bulk_add_favorites(
|
||||
trackIds: Vec<i64>,
|
||||
bridge: State<'_, CoreBridgeState>,
|
||||
cache_state: State<'_, crate::config::favorites_cache::FavoritesCacheState>,
|
||||
runtime: State<'_, RuntimeManagerState>,
|
||||
) -> Result<(), RuntimeError> {
|
||||
runtime
|
||||
.manager()
|
||||
.check_requirements(CommandRequirement::RequiresCoreBridgeAuth)
|
||||
.await?;
|
||||
log::info!("[V2] bulk_add_favorites: {} tracks", trackIds.len());
|
||||
let bridge = bridge.get().await;
|
||||
// Phase 1: API calls (async — no lock held across awaits)
|
||||
for id in &trackIds {
|
||||
bridge
|
||||
.add_favorite("track", &id.to_string())
|
||||
.await
|
||||
.map_err(RuntimeError::Internal)?;
|
||||
}
|
||||
// Phase 2: cache update (sync, lock acquired and released atomically)
|
||||
{
|
||||
let guard = cache_state
|
||||
.store
|
||||
.lock()
|
||||
.map_err(|_| RuntimeError::Internal("Failed to lock favorites cache".to_string()))?;
|
||||
if let Some(store) = guard.as_ref() {
|
||||
for id in &trackIds {
|
||||
let _ = store.add_favorite_track(*id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Clear favorites cache (V2)
|
||||
#[tauri::command]
|
||||
pub async fn v2_clear_favorites_cache(
|
||||
|
||||
@@ -992,6 +992,8 @@ pub fn run() {
|
||||
commands_v2::v2_clear_queue,
|
||||
commands_v2::v2_add_to_queue,
|
||||
commands_v2::v2_add_to_queue_next,
|
||||
commands_v2::v2_bulk_add_to_queue,
|
||||
commands_v2::v2_bulk_add_to_queue_next,
|
||||
commands_v2::v2_set_queue,
|
||||
commands_v2::v2_remove_from_queue,
|
||||
commands_v2::v2_remove_upcoming_track,
|
||||
@@ -1105,6 +1107,7 @@ pub fn run() {
|
||||
commands_v2::v2_sync_cached_favorite_tracks,
|
||||
commands_v2::v2_cache_favorite_track,
|
||||
commands_v2::v2_uncache_favorite_track,
|
||||
commands_v2::v2_bulk_add_favorites,
|
||||
commands_v2::v2_clear_favorites_cache,
|
||||
commands_v2::v2_get_cached_favorite_albums,
|
||||
commands_v2::v2_sync_cached_favorite_albums,
|
||||
|
||||
Reference in new issue
Block a user