feat(cache): centralize absolute URL generation with PMO_SERVER_URL

Replace hardcoded relative URLs and manual base_url concatenation with a unified absolute URL API via pmocache::covers_absolute_url_for() and CacheTrait::absolute_url_for().

- Add pmocache as a required dependency to pmoparadise
- Introduce absolute_url_for() and covers_absolute_url_for() helpers using PMO_SERVER_URL env var (default: http://localhost:8080)
- Update all callers to use absolute URLs for covers and audio in streaming, playlists, Qobuz, Radio France, UPnP, and server startup
- Remove redundant route_for() usage in URL construction
- Add pmocache to Cargo.lock
This commit is contained in:
2026-03-24 12:02:53 +01:00
parent b690420550
commit 1164a11410
12 changed files with 51 additions and 41 deletions

View File

@@ -69,14 +69,7 @@ pub trait FileCache<C: CacheConfig>: Send + Sync {
/// Retourne la route relative pour accéder à un item du cache
///
/// # Arguments
///
/// * `pk` - Clé primaire de la piste
/// * `param` - Paramètre optionnel (ex: "orig", "128k", etc.)
///
/// # Returns
///
/// Route relative (ex: "/audio/flac/abc123" ou "/audio/tracks/abc123/orig")
/// Format: `/{cache_name}/{cache_type}/{pk}[/{param}]`
fn route_for(&self, pk: &str, param: Option<&str>) -> String {
if let Some(p) = param {
format!("/{}/{}/{}/{}", C::cache_name(), C::cache_type(), pk, p)
@@ -85,6 +78,16 @@ pub trait FileCache<C: CacheConfig>: Send + Sync {
}
}
/// Retourne l'URL absolue pour accéder à un item du cache
///
/// Utilise la variable d'environnement `PMO_SERVER_URL` comme base,
/// avec `http://localhost:8080` comme valeur par défaut.
fn absolute_url_for(&self, pk: &str, param: Option<&str>) -> String {
let base = std::env::var("PMO_SERVER_URL")
.unwrap_or_else(|_| "http://localhost:8080".to_string());
format!("{}{}", base.trim_end_matches('/'), self.route_for(pk, param))
}
/// Télécharge un fichier depuis une URL et l'ajoute au cache
///
/// # Arguments

View File

@@ -144,6 +144,22 @@ pub use cache::{
CacheSubscription,
};
pub use cache_trait::{pk_from_content_header, FileCache};
/// Retourne la route relative pour une cover: `/covers/image/{pk}[/{param}]`
pub fn covers_route_for(pk: &str, param: Option<&str>) -> String {
if let Some(p) = param {
format!("/covers/image/{}/{}", pk, p)
} else {
format!("/covers/image/{}", pk)
}
}
/// Retourne l'URL absolue pour une cover via `PMO_SERVER_URL`
pub fn covers_absolute_url_for(pk: &str, param: Option<&str>) -> String {
let base = std::env::var("PMO_SERVER_URL")
.unwrap_or_else(|_| "http://localhost:8080".to_string());
format!("{}{}", base.trim_end_matches('/'), covers_route_for(pk, param))
}
pub use db::{CacheEntry, DB};
pub use download::{
download, download_with_transformer, ingest_with_transformer, peek_header, peek_reader_header,