Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fix: Handle null images for playlist #716

Merged
merged 4 commits into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does #[serde(default)] fix the issue?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprisingly, no. I haven't investigated why but adding that to the images will still throw a null-errror.

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
Loading