refactor(v2): inline offline scrobble/playlist delegates
Inlines the bodies of `create_pending_playlist`, `get_pending_playlist_count`, `queue_scrobble`, `get_queued_scrobbles`, `get_queued_scrobble_count`, and `cleanup_sent_scrobbles` from crate::offline::commands::* directly into commands_v2/legacy_compat.rs. The legacy bodies were uniform: lock state.store, unwrap optional store, delegate to a method on the store struct. Inlined verbatim with the String error type mapped to RuntimeError::Internal at each return path. The store-side OfflineStore methods (data layer) are untouched. Deletes the legacy #[tauri::command] definitions in offline/mod.rs. Other functions in the offline::commands module remain (still called from commands_v2/library.rs delegates, which are step 8 scope). No frontend invoke changes required. Step 6 of the legacy cleanup plan, group C (offline scrobble/playlist). cc
This commit is contained in:
2 files changed
+64
-117
No files matched your search
@@ -453,20 +453,36 @@ pub fn v2_create_pending_playlist(
|
||||
localTrackPaths: Vec<String>,
|
||||
state: State<'_, OfflineState>,
|
||||
) -> Result<i64, RuntimeError> {
|
||||
crate::offline::commands::create_pending_playlist(
|
||||
name,
|
||||
description,
|
||||
isPublic,
|
||||
trackIds,
|
||||
localTrackPaths,
|
||||
state,
|
||||
)
|
||||
.map_err(RuntimeError::Internal)
|
||||
let guard__ = state
|
||||
.store
|
||||
.lock()
|
||||
.map_err(|e| RuntimeError::Internal(format!("Lock error: {}", e)))?;
|
||||
let store = guard__
|
||||
.as_ref()
|
||||
.ok_or_else(|| RuntimeError::Internal("No active session - please log in".to_string()))?;
|
||||
store
|
||||
.create_pending_playlist(
|
||||
&name,
|
||||
description.as_deref(),
|
||||
isPublic,
|
||||
&trackIds,
|
||||
&localTrackPaths,
|
||||
)
|
||||
.map_err(RuntimeError::Internal)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn v2_get_pending_playlist_count(state: State<'_, OfflineState>) -> Result<u32, RuntimeError> {
|
||||
crate::offline::commands::get_pending_playlist_count(state).map_err(RuntimeError::Internal)
|
||||
let guard__ = state
|
||||
.store
|
||||
.lock()
|
||||
.map_err(|e| RuntimeError::Internal(format!("Lock error: {}", e)))?;
|
||||
let store = guard__
|
||||
.as_ref()
|
||||
.ok_or_else(|| RuntimeError::Internal("No active session - please log in".to_string()))?;
|
||||
store
|
||||
.get_pending_playlist_count()
|
||||
.map_err(RuntimeError::Internal)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -477,7 +493,15 @@ pub fn v2_queue_scrobble(
|
||||
timestamp: i64,
|
||||
state: State<'_, OfflineState>,
|
||||
) -> Result<i64, RuntimeError> {
|
||||
crate::offline::commands::queue_scrobble(artist, track, album, timestamp, state)
|
||||
let guard__ = state
|
||||
.store
|
||||
.lock()
|
||||
.map_err(|e| RuntimeError::Internal(format!("Lock error: {}", e)))?;
|
||||
let store = guard__
|
||||
.as_ref()
|
||||
.ok_or_else(|| RuntimeError::Internal("No active session - please log in".to_string()))?;
|
||||
store
|
||||
.queue_scrobble(&artist, &track, album.as_deref(), timestamp)
|
||||
.map_err(RuntimeError::Internal)
|
||||
}
|
||||
|
||||
@@ -487,12 +511,30 @@ pub fn v2_get_queued_scrobbles(
|
||||
limit: Option<u32>,
|
||||
state: State<'_, OfflineState>,
|
||||
) -> Result<Vec<crate::offline::QueuedScrobble>, RuntimeError> {
|
||||
crate::offline::commands::get_queued_scrobbles(limit, state).map_err(RuntimeError::Internal)
|
||||
let guard__ = state
|
||||
.store
|
||||
.lock()
|
||||
.map_err(|e| RuntimeError::Internal(format!("Lock error: {}", e)))?;
|
||||
let store = guard__
|
||||
.as_ref()
|
||||
.ok_or_else(|| RuntimeError::Internal("No active session - please log in".to_string()))?;
|
||||
store
|
||||
.get_queued_scrobbles(limit.unwrap_or(50))
|
||||
.map_err(RuntimeError::Internal)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn v2_get_queued_scrobble_count(state: State<'_, OfflineState>) -> Result<u32, RuntimeError> {
|
||||
crate::offline::commands::get_queued_scrobble_count(state).map_err(RuntimeError::Internal)
|
||||
let guard__ = state
|
||||
.store
|
||||
.lock()
|
||||
.map_err(|e| RuntimeError::Internal(format!("Lock error: {}", e)))?;
|
||||
let store = guard__
|
||||
.as_ref()
|
||||
.ok_or_else(|| RuntimeError::Internal("No active session - please log in".to_string()))?;
|
||||
store
|
||||
.get_queued_scrobble_count()
|
||||
.map_err(RuntimeError::Internal)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -501,7 +543,15 @@ pub fn v2_cleanup_sent_scrobbles(
|
||||
olderThanDays: Option<u32>,
|
||||
state: State<'_, OfflineState>,
|
||||
) -> Result<u32, RuntimeError> {
|
||||
crate::offline::commands::cleanup_sent_scrobbles(olderThanDays, state)
|
||||
let guard__ = state
|
||||
.store
|
||||
.lock()
|
||||
.map_err(|e| RuntimeError::Internal(format!("Lock error: {}", e)))?;
|
||||
let store = guard__
|
||||
.as_ref()
|
||||
.ok_or_else(|| RuntimeError::Internal("No active session - please log in".to_string()))?;
|
||||
store
|
||||
.cleanup_sent_scrobbles(olderThanDays.unwrap_or(7))
|
||||
.map_err(RuntimeError::Internal)
|
||||
}
|
||||
|
||||
|
||||
@@ -935,32 +935,6 @@ pub mod commands {
|
||||
|
||||
// === Pending Playlist Sync Commands ===
|
||||
|
||||
/// Create a playlist while offline (queued for sync)
|
||||
#[tauri::command]
|
||||
pub fn create_pending_playlist(
|
||||
name: String,
|
||||
description: Option<String>,
|
||||
is_public: bool,
|
||||
track_ids: Vec<u64>,
|
||||
local_track_paths: Vec<String>,
|
||||
state: State<'_, OfflineState>,
|
||||
) -> Result<i64, String> {
|
||||
let guard__ = state
|
||||
.store
|
||||
.lock()
|
||||
.map_err(|e| format!("Lock error: {}", e))?;
|
||||
let store = guard__
|
||||
.as_ref()
|
||||
.ok_or("No active session - please log in")?;
|
||||
store.create_pending_playlist(
|
||||
&name,
|
||||
description.as_deref(),
|
||||
is_public,
|
||||
&track_ids,
|
||||
&local_track_paths,
|
||||
)
|
||||
}
|
||||
|
||||
/// Get all playlists pending sync
|
||||
#[tauri::command]
|
||||
pub fn get_pending_playlists(
|
||||
@@ -994,19 +968,6 @@ pub mod commands {
|
||||
store.add_tracks_to_pending_playlist(pending_id, &qobuz_track_ids, &local_track_paths)
|
||||
}
|
||||
|
||||
/// Get count of pending playlists
|
||||
#[tauri::command]
|
||||
pub fn get_pending_playlist_count(state: State<'_, OfflineState>) -> Result<u32, String> {
|
||||
let guard__ = state
|
||||
.store
|
||||
.lock()
|
||||
.map_err(|e| format!("Lock error: {}", e))?;
|
||||
let store = guard__
|
||||
.as_ref()
|
||||
.ok_or("No active session - please log in")?;
|
||||
store.get_pending_playlist_count()
|
||||
}
|
||||
|
||||
/// Update Qobuz playlist ID without marking as synced (for partial sync recovery)
|
||||
#[tauri::command]
|
||||
pub fn update_pending_playlist_qobuz_id(
|
||||
@@ -1059,41 +1020,6 @@ pub mod commands {
|
||||
|
||||
// === Scrobble Queue Commands ===
|
||||
|
||||
/// Queue a scrobble for later submission (when offline)
|
||||
#[tauri::command]
|
||||
pub fn queue_scrobble(
|
||||
artist: String,
|
||||
track: String,
|
||||
album: Option<String>,
|
||||
timestamp: i64,
|
||||
state: State<'_, OfflineState>,
|
||||
) -> Result<i64, String> {
|
||||
let guard__ = state
|
||||
.store
|
||||
.lock()
|
||||
.map_err(|e| format!("Lock error: {}", e))?;
|
||||
let store = guard__
|
||||
.as_ref()
|
||||
.ok_or("No active session - please log in")?;
|
||||
store.queue_scrobble(&artist, &track, album.as_deref(), timestamp)
|
||||
}
|
||||
|
||||
/// Get queued scrobbles (up to limit, default 50 for Last.fm batch)
|
||||
#[tauri::command]
|
||||
pub fn get_queued_scrobbles(
|
||||
limit: Option<u32>,
|
||||
state: State<'_, OfflineState>,
|
||||
) -> Result<Vec<QueuedScrobble>, String> {
|
||||
let guard__ = state
|
||||
.store
|
||||
.lock()
|
||||
.map_err(|e| format!("Lock error: {}", e))?;
|
||||
let store = guard__
|
||||
.as_ref()
|
||||
.ok_or("No active session - please log in")?;
|
||||
store.get_queued_scrobbles(limit.unwrap_or(50))
|
||||
}
|
||||
|
||||
/// Mark scrobbles as sent after successful Last.fm submission
|
||||
#[tauri::command]
|
||||
pub fn mark_scrobbles_sent(
|
||||
@@ -1109,33 +1035,4 @@ pub mod commands {
|
||||
.ok_or("No active session - please log in")?;
|
||||
store.mark_scrobbles_sent(&ids)
|
||||
}
|
||||
|
||||
/// Get count of queued (unsent) scrobbles
|
||||
#[tauri::command]
|
||||
pub fn get_queued_scrobble_count(state: State<'_, OfflineState>) -> Result<u32, String> {
|
||||
let guard__ = state
|
||||
.store
|
||||
.lock()
|
||||
.map_err(|e| format!("Lock error: {}", e))?;
|
||||
let store = guard__
|
||||
.as_ref()
|
||||
.ok_or("No active session - please log in")?;
|
||||
store.get_queued_scrobble_count()
|
||||
}
|
||||
|
||||
/// Cleanup old sent scrobbles
|
||||
#[tauri::command]
|
||||
pub fn cleanup_sent_scrobbles(
|
||||
older_than_days: Option<u32>,
|
||||
state: State<'_, OfflineState>,
|
||||
) -> Result<u32, String> {
|
||||
let guard__ = state
|
||||
.store
|
||||
.lock()
|
||||
.map_err(|e| format!("Lock error: {}", e))?;
|
||||
let store = guard__
|
||||
.as_ref()
|
||||
.ok_or("No active session - please log in")?;
|
||||
store.cleanup_sent_scrobbles(older_than_days.unwrap_or(7))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user