diff options
Diffstat (limited to 'src/spotify.rs')
-rw-r--r-- | src/spotify.rs | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/spotify.rs b/src/spotify.rs index ea05b14..04a82bc 100644 --- a/src/spotify.rs +++ b/src/spotify.rs @@ -10,7 +10,8 @@ use std::collections::HashMap; use std::sync::{Arc, Mutex}; lazy_static! { - static ref CACHE: Arc<Mutex<HashMap<String, Spotify>>> = Arc::new(Mutex::new(HashMap::new())); + static ref CACHE: Arc<Mutex<HashMap<String, (String, Spotify)>>> = + Arc::new(Mutex::new(HashMap::new())); } static CHUNK_SIZE: u32 = 50; @@ -113,7 +114,7 @@ fn generate_random_uuid(length: usize) -> String { } pub async fn auth_user(name: &str, code: &str) -> Result<(String, Spotify), Error> { - let mut spotify = { + let (user, mut spotify) = { let mut guard = (*CACHE).lock()?; guard.remove(name)? }; @@ -127,15 +128,15 @@ pub async fn auth_user(name: &str, code: &str) -> Result<(String, Spotify), Erro let spotify = Spotify::default() .client_credentials_manager(client_credential) .build();*/ - let user_id = spotify - .current_user() - .await - .map_err(|e| format!("failed to load currentuser {:?}", e))? - .id; - Ok((user_id, spotify)) + /*let user_id = spotify + .current_user() + .await + .map_err(|e| format!("failed to load currentuser {:?}", e))? + .id;*/ + Ok((user, spotify)) } -pub fn token(name: String) -> Result<String, Error> { +pub fn token(name: String, token: String) -> Result<String, Error> { let scope = "playlist-read-private playlist-read-collaborative user-read-private user-follow-read user-library-read"; let oauth = OAuthBuilder::from_env() @@ -162,6 +163,6 @@ pub fn token(name: String) -> Result<String, Error> { */ //let auth_url = oauth.get_authorize_url(Some(&state), None); let mut guard = (*CACHE).lock()?; - guard.insert(name, spotify); + guard.insert(token, (name, spotify)); Ok(auth_url) } |