fix(album): accept awarded_at as integer or string on PageArtistAward
/album/get returns award.awarded_at as a Unix timestamp integer while /discover/index returns it as a YYYY-MM-DD string — our struct only accepted String, so /album/get started failing with 'invalid type: integer `…`, expected a string' as soon as awards were added to Album in Phase 2. Every 'Load album' call broke. Adds a custom deserializer that accepts both shapes and normalizes to String downstream. Applied in both qbz-models (V2) and src-tauri legacy api::models for symmetry. cc
This commit is contained in:
2 files changed
+74
No files matched your search
@@ -965,9 +965,25 @@ pub struct PageArtistRights {
|
||||
pub struct PageArtistAward {
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
/// Qobuz returns this either as "YYYY-MM-DD" or a Unix timestamp
|
||||
/// integer depending on the endpoint — accept both.
|
||||
#[serde(default, deserialize_with = "deserialize_awarded_at")]
|
||||
pub awarded_at: Option<String>,
|
||||
}
|
||||
|
||||
fn deserialize_awarded_at<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let value = Option::<serde_json::Value>::deserialize(deserializer)?;
|
||||
Ok(match value {
|
||||
Some(serde_json::Value::String(s)) => Some(s),
|
||||
Some(serde_json::Value::Number(n)) => Some(n.to_string()),
|
||||
Some(serde_json::Value::Null) | None => None,
|
||||
Some(_) => None,
|
||||
})
|
||||
}
|
||||
|
||||
/// Track from /artist/page (top_tracks or tracks_appears_on)
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PageArtistTrack {
|
||||
|
||||
Reference in new issue
Block a user