From 4a60f12c523674351b84039236f9eb5468f35fda Mon Sep 17 00:00:00 2001 From: JMARyA Date: Fri, 2 Aug 2024 23:28:32 +0200 Subject: [PATCH] add cover api --- src/library/track.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/library/track.rs b/src/library/track.rs index a2813bc..ee29faa 100644 --- a/src/library/track.rs +++ b/src/library/track.rs @@ -86,13 +86,12 @@ impl Track { impl ToAPI for Track { async fn api(&self) -> serde_json::Value { - let album_title = if let Some(album_ref) = &self.album_id { - album_ref - .get_partial::(json!({"title": 1})) - .await - .title + let (cover, album_title) = if let Some(album_ref) = &self.album_id { + let album = album_ref.get::().await; + + (album.get_cover().await.is_some(), album.title) } else { - None + (false, String::new()) }; let artist_title = if let Some(artist_ref) = &self.artist_id { @@ -111,6 +110,11 @@ impl ToAPI for Track { "meta": serde_json::to_value(&self.meta).unwrap(), "album_id": self.album_id.as_ref().map(|x| x.id().to_string()), "album": album_title, + "cover": if cover { + Some(format!("/album/{}/cover", self._id)) + } else { + None + }, "artist_id": self.artist_id.as_ref().map(|x| x.id().to_string()), "artist": artist_title })