2.2.3
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "spoticord_utils"
|
||||
version = "2.2.2"
|
||||
version = "2.2.3"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
@@ -9,3 +9,4 @@ anyhow = "1.0.86"
|
||||
base64 = "0.22.1"
|
||||
log = "0.4.22"
|
||||
poise = "0.6.1"
|
||||
tokio = { version = "1.40.0", features = ["time"], default-features = false }
|
||||
|
||||
@@ -5,7 +5,8 @@ use librespot::{
|
||||
discovery::Credentials,
|
||||
protocol::{authentication::AuthenticationType, keyexchange::ErrorCode},
|
||||
};
|
||||
use log::trace;
|
||||
use log::debug;
|
||||
use std::time::Duration;
|
||||
|
||||
pub async fn validate_token(
|
||||
username: impl Into<String>,
|
||||
@@ -19,12 +20,12 @@ pub async fn validate_token(
|
||||
auth_data,
|
||||
};
|
||||
|
||||
trace!("Validating session token for {}", credentials.username);
|
||||
debug!("Validating session token for {}", credentials.username);
|
||||
|
||||
let new_credentials = request_session_token(credentials.clone()).await?;
|
||||
|
||||
if credentials.auth_data != new_credentials.auth_data {
|
||||
trace!("New session token retrieved for {}", credentials.username);
|
||||
debug!("New session token retrieved for {}", credentials.username);
|
||||
|
||||
return Ok(Some(BASE64.encode(new_credentials.auth_data)));
|
||||
}
|
||||
@@ -33,14 +34,29 @@ pub async fn validate_token(
|
||||
}
|
||||
|
||||
pub async fn request_session_token(credentials: Credentials) -> Result<Credentials> {
|
||||
trace!("Requesting session token for {}", credentials.username);
|
||||
debug!("Requesting session token for {}", credentials.username);
|
||||
|
||||
let session = Session::new(SessionConfig::default(), None);
|
||||
let mut tries = 0;
|
||||
|
||||
Ok(loop {
|
||||
let (host, port) = session.apresolver().resolve("accesspoint").await?;
|
||||
let mut transport = librespot::core::connection::connect(&host, port, None).await?;
|
||||
|
||||
let mut transport = match librespot::core::connection::connect(&host, port, None).await {
|
||||
Ok(transport) => transport,
|
||||
Err(why) => {
|
||||
// Retry
|
||||
|
||||
tries += 1;
|
||||
if tries > 3 {
|
||||
return Err(why.into());
|
||||
}
|
||||
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
match librespot::core::connection::authenticate(
|
||||
&mut transport,
|
||||
@@ -59,6 +75,8 @@ pub async fn request_session_token(credentials: Credentials) -> Result<Credentia
|
||||
return Err(e.into());
|
||||
}
|
||||
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
|
||||
continue;
|
||||
} else {
|
||||
return Err(e.into());
|
||||
|
||||
Reference in New Issue
Block a user