Skip to content

Commit

Permalink
Handle null images for playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoes1286 authored Jun 25, 2024
1 parent aa1c578 commit 657ba5d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/api/api_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ trait WithImages {
pub struct Playlist {
pub id: String,
pub name: String,
pub images: Vec<Image>,
pub images: Option<Vec<Image>>,
pub tracks: Page<PlaylistTrack>,
pub owner: PlaylistOwner,
}
Expand All @@ -197,9 +197,14 @@ pub struct PlaylistOwner {
pub display_name: String,
}

const def_image: &'static [Image] = &[Image {url: String::new(), height: Some(640), width: Some(640)}];

impl WithImages for Playlist {
fn images(&self) -> &[Image] {
&self.images[..]
match &self.images {
Some(x) => &x[..],
None => &def_image[..],
}
}
}

Expand Down

0 comments on commit 657ba5d

Please sign in to comment.