Optimize album art URL handling and simplify image display logic
This commit refactors the album art URL normalization logic in Rust to use match expressions for cleaner and more concise code. It also simplifies the image display logic in Vue by removing the redundant cacheBustedUrl check, ensuring the image is displayed based solely on load and error states.
This commit is contained in:
@@ -350,20 +350,14 @@ const swipeOpacity = computed(() => {
|
|||||||
@click="openCoverOverlay"
|
@click="openCoverOverlay"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
|
v-if="cacheBustedUrl"
|
||||||
ref="coverImageRef"
|
ref="coverImageRef"
|
||||||
:style="{
|
:style="{
|
||||||
opacity:
|
opacity: imageLoaded && !imageError ? 1 : 0,
|
||||||
cacheBustedUrl && imageLoaded && !imageError ? 1 : 0,
|
visibility: imageLoaded && !imageError ? 'visible' : 'hidden',
|
||||||
visibility:
|
position: imageLoaded && !imageError ? 'relative' : 'absolute',
|
||||||
cacheBustedUrl && imageLoaded && !imageError
|
|
||||||
? 'visible'
|
|
||||||
: 'hidden',
|
|
||||||
position:
|
|
||||||
cacheBustedUrl && imageLoaded && !imageError
|
|
||||||
? 'relative'
|
|
||||||
: 'absolute',
|
|
||||||
}"
|
}"
|
||||||
:src="cacheBustedUrl || ''"
|
:src="cacheBustedUrl"
|
||||||
:alt="metadata?.album || 'Album cover'"
|
:alt="metadata?.album || 'Album cover'"
|
||||||
class="cover-image"
|
class="cover-image"
|
||||||
@load="handleImageLoad"
|
@load="handleImageLoad"
|
||||||
|
|||||||
@@ -517,13 +517,11 @@ impl RadioParadiseSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Normaliser l'albumArtURI : rendre absolu si chemin relatif, sinon fallback par défaut
|
// Normaliser l'albumArtURI : rendre absolu si chemin relatif, sinon fallback par défaut
|
||||||
if let Some(art) = item.album_art.as_mut() {
|
item.album_art = match item.album_art.take() {
|
||||||
if art.starts_with('/') {
|
Some(art) if art.starts_with('/') => Some(format!("{}{}", self.base_url, art)),
|
||||||
*art = format!("{}{}", self.base_url, art);
|
Some(_) => Some(self.default_cover_url()), // URL externe brute → fallback local
|
||||||
}
|
None => Some(self.default_cover_url()),
|
||||||
} else {
|
};
|
||||||
item.album_art = Some(self.default_cover_url());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(items)
|
Ok(items)
|
||||||
@@ -590,13 +588,11 @@ impl RadioParadiseSource {
|
|||||||
item.genre = Some("Radio Paradise".to_string());
|
item.genre = Some("Radio Paradise".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(art) = item.album_art.as_mut() {
|
item.album_art = match item.album_art.take() {
|
||||||
if art.starts_with('/') {
|
Some(art) if art.starts_with('/') => Some(format!("{}{}", self.base_url, art)),
|
||||||
*art = format!("{}{}", self.base_url, art);
|
Some(_) => Some(self.default_cover_url()),
|
||||||
}
|
None => Some(self.default_cover_url()),
|
||||||
} else {
|
};
|
||||||
item.album_art = Some(self.default_cover_url());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(items)
|
Ok(items)
|
||||||
@@ -921,6 +917,13 @@ impl MusicSource for RadioParadiseSource {
|
|||||||
if item.genre.is_none() {
|
if item.genre.is_none() {
|
||||||
item.genre = Some("Radio Paradise".to_string());
|
item.genre = Some("Radio Paradise".to_string());
|
||||||
}
|
}
|
||||||
|
item.album_art = match item.album_art.take() {
|
||||||
|
Some(art) if art.starts_with('/') => {
|
||||||
|
Some(format!("{}{}", self.base_url, art))
|
||||||
|
}
|
||||||
|
Some(_) => Some(self.default_cover_url()),
|
||||||
|
None => Some(self.default_cover_url()),
|
||||||
|
};
|
||||||
adjusted.push(item);
|
adjusted.push(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -987,13 +990,13 @@ impl MusicSource for RadioParadiseSource {
|
|||||||
item.genre = Some("Radio Paradise".to_string());
|
item.genre = Some("Radio Paradise".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(art) = item.album_art.as_mut() {
|
item.album_art = match item.album_art.take() {
|
||||||
if art.starts_with('/') {
|
Some(art) if art.starts_with('/') => {
|
||||||
*art = format!("{}{}", self.base_url, art);
|
Some(format!("{}{}", self.base_url, art))
|
||||||
}
|
}
|
||||||
} else {
|
Some(_) => Some(self.default_cover_url()),
|
||||||
item.album_art = Some(self.default_cover_url());
|
None => Some(self.default_cover_url()),
|
||||||
}
|
};
|
||||||
|
|
||||||
let expected_id =
|
let expected_id =
|
||||||
format!("radio-paradise:channel:{}:liveplaylist:track:{}", slug, pk);
|
format!("radio-paradise:channel:{}:liveplaylist:track:{}", slug, pk);
|
||||||
|
|||||||
Reference in New Issue
Block a user