aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authoralyx <alyx@aleteoryx.me>2024-04-17 16:55:15 -0400
committeralyx <alyx@aleteoryx.me>2024-04-17 16:55:15 -0400
commite9ca1e6b14fe635fb940f5bae8560c68acca3d12 (patch)
tree0ed2f7976d4ffc40efc03a19987a3a14bd35edb6 /src
parentadc1a486faf473eb7d993ca5df78485f0938d1d0 (diff)
downloadlfm_embed-e9ca1e6b14fe635fb940f5bae8560c68acca3d12.tar.gz
lfm_embed-e9ca1e6b14fe635fb940f5bae8560c68acca3d12.tar.bz2
lfm_embed-e9ca1e6b14fe635fb940f5bae8560c68acca3d12.zip
Fix URL escaping issue
Diffstat (limited to 'src')
-rw-r--r--src/cache/user.rs3
1 files changed, 2 insertions, 1 deletions
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!")); }