~aleteoryx/lfm_embed

e9ca1e6b14fe635fb940f5bae8560c68acca3d12 — alyx 6 months ago adc1a48 master
Fix URL escaping issue
1 files changed, 2 insertions(+), 1 deletions(-)

M src/cache/user.rs
M src/cache/user.rs => src/cache/user.rs +2 -1
@@ 5,6 5,7 @@ use std::sync::LazyLock;

use tokio::sync::RwLock;
use reqwest::{StatusCode, Client};
use urlencoding::encode as urlencode;

use super::{CacheFuture, CacheGetter, Cache, AsyncCache};
use crate::deserialize::{User, Track, TrackStub};


@@ 50,7 51,7 @@ fn user_getter(username: &String) -> UserFuture {
      .recenttracks.track.into_iter().next().ok_or((StatusCode::UNPROCESSABLE_ENTITY, "You need to listen to some songs first!"))?;
    log::trace!("Parsed into: {trackstub:?}");

    let trackreq = HTTP.get(format!("https://ws.audioscrobbler.com/2.0/?method=track.getInfo&format=json&username={username}&api_key={}&track={}&artist={}", CONFIG.lastfm_api_key, trackstub.name, trackstub.artist.name))
    let trackreq = HTTP.get(format!("https://ws.audioscrobbler.com/2.0/?method=track.getInfo&format=json&username={username}&api_key={}&track={}&artist={}", CONFIG.lastfm_api_key, urlencode(&trackstub.name), urlencode(&trackstub.artist.name)))
      .send().await
      .map_err(|e| {log::error!("Failed to get tracks for user `{username}`: {e}"); (StatusCode::SERVICE_UNAVAILABLE, "Couldn't connect to last.fm!")})?;
    if trackreq.status() == StatusCode::NOT_FOUND { return Err((StatusCode::NOT_FOUND, "Track does not exist!")); }