feat: add API Keys settings section for user-provided credentials
- Add api_keys module with store for user-provided credentials (Spotify, Tidal, Discogs) - Add commands to get/set/clear credentials for each provider - Update providers to check user credentials first (priority: user > embedded > env) - Add collapsible API Keys section to SettingsView - Show status badges (Active, Custom, Not configured) for each provider - Store user credentials in localStorage with backend sync
This commit is contained in:
1 parent
3e58803962
commit
eefec87d91
11 files changed
+861
-37
No files matched your search
@@ -2,14 +2,41 @@
|
||||
|
||||
use tauri::State;
|
||||
|
||||
use crate::playlist_import::{import_public_playlist, preview_public_playlist, ImportPlaylist, ImportSummary};
|
||||
use crate::api_keys::ApiKeysState;
|
||||
use crate::playlist_import::{
|
||||
import_public_playlist, preview_public_playlist, ImportPlaylist, ImportSummary,
|
||||
ProviderCredentials,
|
||||
};
|
||||
use crate::AppState;
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn playlist_import_preview(url: String) -> Result<ImportPlaylist, String> {
|
||||
pub async fn playlist_import_preview(
|
||||
url: String,
|
||||
api_keys: State<'_, ApiKeysState>,
|
||||
) -> Result<ImportPlaylist, String> {
|
||||
log::info!("Command: playlist_import_preview {}", url);
|
||||
|
||||
preview_public_playlist(&url)
|
||||
// Get user-provided credentials from state
|
||||
let keys = api_keys.lock().await;
|
||||
let spotify_creds = if keys.spotify.is_set() {
|
||||
Some(ProviderCredentials {
|
||||
client_id: keys.spotify.client_id.clone(),
|
||||
client_secret: keys.spotify.client_secret.clone(),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let tidal_creds = if keys.tidal.is_set() {
|
||||
Some(ProviderCredentials {
|
||||
client_id: keys.tidal.client_id.clone(),
|
||||
client_secret: keys.tidal.client_secret.clone(),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
drop(keys);
|
||||
|
||||
preview_public_playlist(&url, spotify_creds, tidal_creds)
|
||||
.await
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
@@ -20,15 +47,38 @@ pub async fn playlist_import_execute(
|
||||
name_override: Option<String>,
|
||||
is_public: Option<bool>,
|
||||
state: State<'_, AppState>,
|
||||
api_keys: State<'_, ApiKeysState>,
|
||||
) -> Result<ImportSummary, String> {
|
||||
log::info!("Command: playlist_import_execute {}", url);
|
||||
|
||||
// Get user-provided credentials from state
|
||||
let keys = api_keys.lock().await;
|
||||
let spotify_creds = if keys.spotify.is_set() {
|
||||
Some(ProviderCredentials {
|
||||
client_id: keys.spotify.client_id.clone(),
|
||||
client_secret: keys.spotify.client_secret.clone(),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let tidal_creds = if keys.tidal.is_set() {
|
||||
Some(ProviderCredentials {
|
||||
client_id: keys.tidal.client_id.clone(),
|
||||
client_secret: keys.tidal.client_secret.clone(),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
drop(keys);
|
||||
|
||||
let client = state.client.lock().await;
|
||||
import_public_playlist(
|
||||
&url,
|
||||
&client,
|
||||
name_override.as_deref(),
|
||||
is_public.unwrap_or(false),
|
||||
spotify_creds,
|
||||
tidal_creds,
|
||||
)
|
||||
.await
|
||||
.map_err(|e| e.to_string())
|
||||
|
||||
Reference in new issue
Block a user