From e9ca1e6b14fe635fb940f5bae8560c68acca3d12 Mon Sep 17 00:00:00 2001 From: alyx Date: Wed, 17 Apr 2024 16:55:15 -0400 Subject: Fix URL escaping issue --- src/cache/user.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/cache') diff --git a/src/cache/user.rs b/src/cache/user.rs index b05d0d1..91c496c 100644 --- a/src/cache/user.rs +++ b/src/cache/user.rs @@ -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!")); } -- cgit v1.2.3-70-g09d2