Skip to content

Commit

Permalink
Bug Fix: Handle null images for playlist (#716)
Browse files Browse the repository at this point in the history
* Handle null images for playlist

* Formating changes

* Formatting changes again

---------

Co-authored-by: Diegovsky (Diego Augusto) <46163903+Diegovsky@users.noreply.github.com>
  • Loading branch information
potatoes1286 and Diegovsky committed Jul 25, 2024
1 parent f71cdf3 commit cd55228
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 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,18 @@ pub struct PlaylistOwner {
pub display_name: String,
}

const EMPTY_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 => &EMPTY_IMAGE[..],
}
}
}

Expand Down

0 comments on commit cd55228

Please sign in to comment.