fix(release-watch): backfill album.artist from artists[0] on getNewReleases

AlbumDto from Qobuz carries both legacy singular 'artist' and current
'artists[]' array. /favorite/getNewReleases omits the singular field
and only populates the array, so our Album struct (which has a default
serde Artist) deserialized an empty name — every Release Watch card on
Home read 'Unknown Artist'.

Pre-process the JSON response items before deserializing: when 'artist'
is absent or null, copy artists[0] into it. Keeps the rest of the
album-list plumbing untouched.

cc
This commit is contained in:
vicrodh committed 2026-04-14 10:40:42 -06:00
1 parent de056abd8a
commit 060395885b
1 file changed
+28 -1
+28 -1
View File
@@ -825,7 +825,34 @@ impl QobuzClient {
// and the caller already knows the offset/limit it asked for, so
// we project onto SearchResultsPage<Album> to stay compatible with
// the rest of the album-list plumbing.
let items_value = response.get("items").cloned().unwrap_or(Value::Null);
//
// Note on shape: AlbumDto carries both `artist` (singular, legacy)
// and `artists` (array, current). `/favorite/getNewReleases` tends
// to omit `artist` and only populate `artists[]`, which made our
// `Album` struct deserialize an empty `artist` and the UI show
// "Unknown Artist". Backfill `artist` from `artists[0]` before
// parsing so the existing deserializer just works.
let mut items_value = response.get("items").cloned().unwrap_or(Value::Null);
if let Some(items_arr) = items_value.as_array_mut() {
for item in items_arr {
if let Some(obj) = item.as_object_mut() {
let needs_backfill = obj
.get("artist")
.map(|v| v.is_null())
.unwrap_or(true);
if needs_backfill {
if let Some(first_artist) = obj
.get("artists")
.and_then(|a| a.as_array())
.and_then(|arr| arr.first())
.cloned()
{
obj.insert("artist".to_string(), first_artist);
}
}
}
}
}
let items: Vec<Album> = serde_json::from_value(items_value).map_err(|e| {
log::warn!(
"[API] get_release_watch items parse error: {}. Body (first 600 chars): {}",