refactor(v2): route library flows through shared impls and remove command-to-command calls
cx
This commit is contained in:
1 parent
d2a13ba95e
commit
ee5998533d
3 files changed
+82
-24
No files matched your search
@@ -45,7 +45,6 @@ use std::fs;
|
|||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use crate::{library as legacy_library};
|
|
||||||
|
|
||||||
// ==================== Helper Functions ====================
|
// ==================== Helper Functions ====================
|
||||||
|
|
||||||
@@ -5326,56 +5325,56 @@ pub async fn v2_start_legacy_migration(
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn v2_library_scan(
|
pub async fn v2_library_scan(
|
||||||
state: State<'_, legacy_library::commands::LibraryState>,
|
state: State<'_, crate::library::LibraryState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
legacy_library::commands::library_scan(state).await
|
crate::library::library_scan_impl(state).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn v2_library_stop_scan(
|
pub async fn v2_library_stop_scan(
|
||||||
state: State<'_, legacy_library::commands::LibraryState>,
|
state: State<'_, crate::library::LibraryState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
legacy_library::commands::library_stop_scan(state).await
|
crate::library::library_stop_scan_impl(state).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn v2_library_scan_folder(
|
pub async fn v2_library_scan_folder(
|
||||||
folder_id: i64,
|
folder_id: i64,
|
||||||
state: State<'_, legacy_library::commands::LibraryState>,
|
state: State<'_, crate::library::LibraryState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
legacy_library::commands::library_scan_folder(folder_id, state).await
|
crate::library::library_scan_folder_impl(folder_id, state).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn v2_library_clear(
|
pub async fn v2_library_clear(
|
||||||
state: State<'_, legacy_library::commands::LibraryState>,
|
state: State<'_, crate::library::LibraryState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
legacy_library::commands::library_clear(state).await
|
crate::library::library_clear_impl(state).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn v2_library_update_album_metadata(
|
pub async fn v2_library_update_album_metadata(
|
||||||
request: legacy_library::commands::LibraryAlbumMetadataUpdateRequest,
|
request: crate::library::LibraryAlbumMetadataUpdateRequest,
|
||||||
state: State<'_, legacy_library::commands::LibraryState>,
|
state: State<'_, crate::library::LibraryState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
legacy_library::commands::library_update_album_metadata(request, state).await
|
crate::library::library_update_album_metadata_impl(request, state).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn v2_library_write_album_metadata_to_files(
|
pub async fn v2_library_write_album_metadata_to_files(
|
||||||
app: tauri::AppHandle,
|
app: tauri::AppHandle,
|
||||||
request: legacy_library::commands::LibraryAlbumMetadataUpdateRequest,
|
request: crate::library::LibraryAlbumMetadataUpdateRequest,
|
||||||
state: State<'_, legacy_library::commands::LibraryState>,
|
state: State<'_, crate::library::LibraryState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
legacy_library::commands::library_write_album_metadata_to_files(app, request, state).await
|
crate::library::library_write_album_metadata_to_files_impl(app, request, state).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn v2_library_refresh_album_metadata_from_files(
|
pub async fn v2_library_refresh_album_metadata_from_files(
|
||||||
album_group_key: String,
|
album_group_key: String,
|
||||||
state: State<'_, legacy_library::commands::LibraryState>,
|
state: State<'_, crate::library::LibraryState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
legacy_library::commands::library_refresh_album_metadata_from_files(album_group_key, state).await
|
crate::library::library_refresh_album_metadata_from_files_impl(album_group_key, state).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
|
|||||||
@@ -474,7 +474,7 @@ pub async fn library_check_folder_accessible(path: String) -> Result<bool, Strin
|
|||||||
// === Scanning ===
|
// === Scanning ===
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn library_scan(state: State<'_, LibraryState>) -> Result<(), String> {
|
pub async fn library_scan_impl(state: State<'_, LibraryState>) -> Result<(), String> {
|
||||||
log::info!("Command: library_scan");
|
log::info!("Command: library_scan");
|
||||||
|
|
||||||
// Get folders to scan
|
// Get folders to scan
|
||||||
@@ -799,7 +799,7 @@ pub async fn library_get_scan_progress(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn library_stop_scan(state: State<'_, LibraryState>) -> Result<(), String> {
|
pub async fn library_stop_scan_impl(state: State<'_, LibraryState>) -> Result<(), String> {
|
||||||
log::info!("Command: library_stop_scan");
|
log::info!("Command: library_stop_scan");
|
||||||
state.scan_cancel.store(true, Ordering::Relaxed);
|
state.scan_cancel.store(true, Ordering::Relaxed);
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -807,7 +807,7 @@ pub async fn library_stop_scan(state: State<'_, LibraryState>) -> Result<(), Str
|
|||||||
|
|
||||||
/// Scan a single folder (by ID)
|
/// Scan a single folder (by ID)
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn library_scan_folder(
|
pub async fn library_scan_folder_impl(
|
||||||
folder_id: i64,
|
folder_id: i64,
|
||||||
state: State<'_, LibraryState>,
|
state: State<'_, LibraryState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
@@ -1169,7 +1169,7 @@ pub async fn library_get_stats(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn library_clear(state: State<'_, LibraryState>) -> Result<(), String> {
|
pub async fn library_clear_impl(state: State<'_, LibraryState>) -> Result<(), String> {
|
||||||
log::info!("Command: library_clear");
|
log::info!("Command: library_clear");
|
||||||
|
|
||||||
let guard__ = state.db.lock().await;
|
let guard__ = state.db.lock().await;
|
||||||
@@ -1841,7 +1841,7 @@ pub struct LibraryAlbumMetadataUpdateRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn library_update_album_metadata(
|
pub async fn library_update_album_metadata_impl(
|
||||||
request: LibraryAlbumMetadataUpdateRequest,
|
request: LibraryAlbumMetadataUpdateRequest,
|
||||||
state: State<'_, LibraryState>,
|
state: State<'_, LibraryState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
@@ -1940,7 +1940,7 @@ pub async fn library_update_album_metadata(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn library_write_album_metadata_to_files(
|
pub async fn library_write_album_metadata_to_files_impl(
|
||||||
app: tauri::AppHandle,
|
app: tauri::AppHandle,
|
||||||
request: LibraryAlbumMetadataUpdateRequest,
|
request: LibraryAlbumMetadataUpdateRequest,
|
||||||
state: State<'_, LibraryState>,
|
state: State<'_, LibraryState>,
|
||||||
@@ -2123,7 +2123,7 @@ pub async fn library_write_album_metadata_to_files(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn library_refresh_album_metadata_from_files(
|
pub async fn library_refresh_album_metadata_from_files_impl(
|
||||||
album_group_key: String,
|
album_group_key: String,
|
||||||
state: State<'_, LibraryState>,
|
state: State<'_, LibraryState>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
@@ -2867,3 +2867,52 @@ pub async fn move_playlist_to_folder(
|
|||||||
db.move_playlist_to_folder(playlist_id, folder_id.as_deref())
|
db.move_playlist_to_folder(playlist_id, folder_id.as_deref())
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Shared wrappers to keep legacy command names while exposing non-command impls for V2 usage.
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn library_scan(state: State<'_, LibraryState>) -> Result<(), String> {
|
||||||
|
library_scan_impl(state).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn library_stop_scan(state: State<'_, LibraryState>) -> Result<(), String> {
|
||||||
|
library_stop_scan_impl(state).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn library_scan_folder(
|
||||||
|
folder_id: i64,
|
||||||
|
state: State<'_, LibraryState>,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
library_scan_folder_impl(folder_id, state).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn library_clear(state: State<'_, LibraryState>) -> Result<(), String> {
|
||||||
|
library_clear_impl(state).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn library_update_album_metadata(
|
||||||
|
request: LibraryAlbumMetadataUpdateRequest,
|
||||||
|
state: State<'_, LibraryState>,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
library_update_album_metadata_impl(request, state).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn library_write_album_metadata_to_files(
|
||||||
|
app: tauri::AppHandle,
|
||||||
|
request: LibraryAlbumMetadataUpdateRequest,
|
||||||
|
state: State<'_, LibraryState>,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
library_write_album_metadata_to_files_impl(app, request, state).await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn library_refresh_album_metadata_from_files(
|
||||||
|
album_group_key: String,
|
||||||
|
state: State<'_, LibraryState>,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
library_refresh_album_metadata_from_files_impl(album_group_key, state).await
|
||||||
|
}
|
||||||
@@ -53,6 +53,16 @@ pub mod thumbnails {
|
|||||||
|
|
||||||
// Re-export commands::LibraryState for compatibility
|
// Re-export commands::LibraryState for compatibility
|
||||||
pub use commands::LibraryState;
|
pub use commands::LibraryState;
|
||||||
|
pub use commands::{
|
||||||
|
LibraryAlbumMetadataUpdateRequest,
|
||||||
|
library_scan_impl,
|
||||||
|
library_stop_scan_impl,
|
||||||
|
library_scan_folder_impl,
|
||||||
|
library_clear_impl,
|
||||||
|
library_update_album_metadata_impl,
|
||||||
|
library_write_album_metadata_to_files_impl,
|
||||||
|
library_refresh_album_metadata_from_files_impl,
|
||||||
|
};
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::atomic::AtomicBool;
|
use std::sync::atomic::AtomicBool;
|
||||||
|
|||||||
Reference in new issue
Block a user