From 22c2e4e2db9ad9d892ed5fb63d92254677f6dafd Mon Sep 17 00:00:00 2001 From: alyx Date: Mon, 1 Apr 2024 19:00:57 -0400 Subject: Reliable user info; Font refactor Hit a few more endpoints to fix missing images, fallback to default album art just in case. Refactor the font cache into its own file. --- src/ctx.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/ctx.rs') diff --git a/src/ctx.rs b/src/ctx.rs index d564bd6..0b250b1 100644 --- a/src/ctx.rs +++ b/src/ctx.rs @@ -40,7 +40,7 @@ pub mod model { pub name: Arc, /// A link to their current image. - pub image_url: Arc, +// pub image_url: Arc, /// A link to their last.fm page. pub url: Arc } @@ -106,10 +106,10 @@ pub mod model { pub struct ResponseCtx(pub model::Root, pub StatusCode); impl ResponseCtx { - pub async fn create(api_result: Result, (StatusCode, &'static str)>, font_query: Option, query: BTreeMap) -> ResponseCtx { + pub async fn create(api_result: Result, (StatusCode, &'static str)>, font_query: Option, query: BTreeMap) -> ResponseCtx { match api_result { Ok(a) => { - let (user, track) = a.as_ref(); + let (user, track, trackstub) = a.as_ref(); ResponseCtx((model::Data { user: model::User { name: user.name.clone(), @@ -129,11 +129,11 @@ impl ResponseCtx { album: track.album.name.clone(), artist: model::Artist { name: track.artist.name.clone(), - image_url: track.artist.images.iter().max_by(|a, b| a.size.cmp(&b.size)).map(|a| a.url.clone()).unwrap_or_else(|| "".into()), +// image_url: track.artist.images.iter().max_by(|a, b| a.size.cmp(&b.size)).map(|a| a.url.clone()).unwrap_or_else(|| "".into()), url: track.artist.url.clone().unwrap_or_else(|| "".into()) }, - image_url: track.images.iter().max_by(|a, b| a.size.cmp(&b.size)).map(|a| a.url.clone()).unwrap_or_else(|| "".into()), - now_playing: track.attr.nowplaying, + image_url: track.images.iter().max_by(|a, b| a.size.cmp(&b.size)).map(|a| a.url.clone()).filter(|s| !s.is_empty()).unwrap_or_else(|| "https://lastfm.freetls.fastly.net/i/u/128s/4128a6eb29f94943c9d206c08e625904.jpg".into()), + now_playing: trackstub.attr.nowplaying, url: track.url.clone(), loved: track.loved.unwrap_or(false) }, -- cgit v1.2.3-54-g00ecf