From a139d3efe397ad0943308ca436d4a85fa6a812b6 Mon Sep 17 00:00:00 2001 From: Scott Lyons Date: Sat, 10 Aug 2024 19:34:17 -0700 Subject: [PATCH] fix(client): fixing tokens to not be encoded wholesale Query tokens weren't working because they were being encoded entirely. Switched to encoding the key and value separately --- szurubooru-client/src/client.rs | 9 +++++++-- szurubooru-client/src/tokens.rs | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/szurubooru-client/src/client.rs b/szurubooru-client/src/client.rs index 5f07556..fe4039f 100644 --- a/szurubooru-client/src/client.rs +++ b/szurubooru-client/src/client.rs @@ -1153,12 +1153,17 @@ impl<'a> SzurubooruRequest<'a> { pub async fn delete_comment(&self, comment_id: u32, version: u32) -> SzurubooruResult<()> { let path = format!("/comment/{comment_id}"); let version_obj = ResourceVersion { version }; - self.do_request(Method::DELETE, &path, None, Some(&version_obj)) + self.do_request::(Method::DELETE, &path, None, Some(&version_obj)) .await + .map(|_| ()) } /// Updates score of authenticated user for given comment. Valid scores are -1, 0 and 1. - pub async fn rate_comment(&self, comment_id: u32, score: i8) -> SzurubooruResult<()> { + pub async fn rate_comment( + &self, + comment_id: u32, + score: i8, + ) -> SzurubooruResult { let path = format!("/comment/{comment_id}/score"); let rating = RateResource { score }; self.do_request(Method::PUT, &path, None, Some(&rating)) diff --git a/szurubooru-client/src/tokens.rs b/szurubooru-client/src/tokens.rs index 3377a42..f6f0eb5 100644 --- a/szurubooru-client/src/tokens.rs +++ b/szurubooru-client/src/tokens.rs @@ -143,18 +143,18 @@ impl QueryToken { impl Display for QueryToken { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let suffix = if !self.value.is_empty() { - format!(":{}", self.value) + format!(":{}", encode(&self.value)) } else { "".to_string() }; - write!(f, "{}{}", self.key, suffix) + write!(f, "{}{}", encode(&self.key), suffix) } } impl ToQueryString for Vec { fn to_query_string(&self) -> String { let query_vec: Vec = self.iter().map(|qv| qv.to_string()).collect(); - encode(&query_vec.join(" ")).to_string() + query_vec.join(" ") } }