aboutsummaryrefslogtreecommitdiffstats
path: root/src/ctx.rs
diff options
context:
space:
mode:
authoralyx <alyx@aleteoryx.me>2024-04-01 19:00:57 -0400
committeralyx <alyx@aleteoryx.me>2024-04-01 19:00:57 -0400
commit22c2e4e2db9ad9d892ed5fb63d92254677f6dafd (patch)
treec3132945f32d1ca5741848a504b48f09a599bafb /src/ctx.rs
parentdc6875ce18a48d314f0576528ebd7dc9e5e2a1b8 (diff)
downloadlfm_embed-22c2e4e2db9ad9d892ed5fb63d92254677f6dafd.tar.gz
lfm_embed-22c2e4e2db9ad9d892ed5fb63d92254677f6dafd.tar.bz2
lfm_embed-22c2e4e2db9ad9d892ed5fb63d92254677f6dafd.zip
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.
Diffstat (limited to 'src/ctx.rs')
-rw-r--r--src/ctx.rs12
1 files changed, 6 insertions, 6 deletions
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<str>,
/// A link to their current image.
- pub image_url: Arc<str>,
+// pub image_url: Arc<str>,
/// A link to their last.fm page.
pub url: Arc<str>
}
@@ -106,10 +106,10 @@ pub mod model {
pub struct ResponseCtx(pub model::Root, pub StatusCode);
impl ResponseCtx {
- pub async fn create(api_result: Result<Arc<(de::User, de::Track)>, (StatusCode, &'static str)>, font_query: Option<FontQuery>, query: BTreeMap<String, String>) -> ResponseCtx {
+ pub async fn create(api_result: Result<Arc<(de::User, de::Track, de::TrackStub)>, (StatusCode, &'static str)>, font_query: Option<FontQuery>, query: BTreeMap<String, String>) -> 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)
},