(feat) Use async cover URL transformation in SSE endpoints

- Replace sync proxy_cover_url_sync calls with async versions using dedicated tokio runtime in transformCoverUrlSync
- Update comments to reflect usage of asynchronous logic for cover URL transformation
This commit is contained in:
2026-04-04 12:41:36 +02:00
parent 21ea77eadc
commit e0ef485e04
2 changed files with 17 additions and 10 deletions

View File

@@ -196,7 +196,7 @@ async fn get_renderer_full_snapshot(
let base_url_str = pmoserver::get_base_url_from_request(&headers);
let base_url = pmoserver::BaseUrl(base_url_str);
// Transform cover URLs in current_track
// Transform cover URLs in current_track using async version
if let Some(ref mut current_track) = snapshot.state.current_track {
if let Some(ref album_art) = current_track.album_art_uri {
if let Some(transformed) = transform_cover_url(Some(album_art), &base_url).await {
@@ -241,7 +241,7 @@ async fn get_renderer_queue(
let base_url_str = pmoserver::get_base_url_from_request(&headers);
let base_url = pmoserver::BaseUrl(base_url_str);
// Transform cover URLs in all queue items
// Transform cover URLs in all queue items using async version
for item in &mut snapshot.queue.items {
if let Some(ref album_art) = item.album_art_uri {
if let Some(transformed) = transform_cover_url(Some(album_art), &base_url).await {

View File

@@ -73,7 +73,7 @@ async fn transform_cover_url(url: Option<&str>, base_url: &pmoserver::BaseUrl) -
/// Transforme une URL de cover pour qu'elle soit accessible depuis le client (version synchrone)
///
/// Utilise la version sync de proxy_cover_url directement.
/// Utilise un thread séparé avec son propre runtime tokio.
#[cfg(feature = "pmoserver")]
fn transform_cover_url_sync(url: Option<&str>, base_url: &pmoserver::BaseUrl) -> Option<String> {
let url = url?;
@@ -88,13 +88,20 @@ fn transform_cover_url_sync(url: Option<&str>, base_url: &pmoserver::BaseUrl) ->
return Some(url.to_string());
}
// Pour les autres URLs, utiliser proxy_cover_url_sync
match pmocovers::proxy_cover_url_sync(url, base_url) {
Ok(local_url) => Some(local_url),
Err(e) => {
tracing::warn!("Failed to proxy cover URL {}: {}", url, e);
Some(url.to_string())
}
// Pour les autres URLs, utiliser un thread avec runtime
let url_owned = url.to_string();
let base_url_owned = base_url.0.clone();
let result = std::thread::spawn(move || {
let runtime = tokio::runtime::Runtime::new().unwrap();
runtime.block_on(async move {
pmocovers::proxy_cover_url(&url_owned, &pmoserver::BaseUrl(base_url_owned)).await
})
}).join();
match result {
Ok(Ok(local_url)) => Some(local_url),
_ => Some(url.to_string())
}
}