From e243d5b64e69f19fd38d6e820ef278317247e090 Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Fri, 18 Apr 2025 13:16:17 +0100 Subject: [PATCH] fix themezer --- sphaira/include/download.hpp | 3 +++ sphaira/source/download.cpp | 10 ++++++++++ sphaira/source/ui/menus/themezer.cpp | 6 ++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/sphaira/include/download.hpp b/sphaira/include/download.hpp index 0c2e6eb..4544ee3 100644 --- a/sphaira/include/download.hpp +++ b/sphaira/include/download.hpp @@ -87,6 +87,9 @@ auto ToFile(const Api& e) -> ApiResult; auto ToMemoryAsync(const Api& e) -> bool; auto ToFileAsync(const Api& e) -> bool; +// uses curl to convert string to their %XX +auto EscapeString(const std::string& str) -> std::string; + struct Api { Api() = default; diff --git a/sphaira/source/download.cpp b/sphaira/source/download.cpp index 64163e6..374e715 100644 --- a/sphaira/source/download.cpp +++ b/sphaira/source/download.cpp @@ -757,4 +757,14 @@ auto ToFileAsync(const Api& e) -> bool { return g_thread_queue.Add(e); } +auto EscapeString(const std::string& str) -> std::string { + std::string result; + const auto s = curl_escape(str.data(), str.length()); + if (s) { + result = s; + curl_free(s); + } + return result; +} + } // namespace sphaira::curl diff --git a/sphaira/source/ui/menus/themezer.cpp b/sphaira/source/ui/menus/themezer.cpp index cd7db79..32d1536 100644 --- a/sphaira/source/ui/menus/themezer.cpp +++ b/sphaira/source/ui/menus/themezer.cpp @@ -68,7 +68,7 @@ auto apiBuildUrlListInternal(const Config& e, bool is_pack) -> std::string { if (is_pack) { cmd = "packList"; // fields += ",themes{id,creator{display_name},details{name,description},last_updated,dl_count,like_count,target,preview{original,thumb}}"; - fields += ",themes{id, preview{thumb}}"; + fields += ",themes{id,preview{thumb}}"; } else { cmd = "themeList"; p0 += ",$target:String"; @@ -92,7 +92,9 @@ auto apiBuildUrlListInternal(const Config& e, bool is_pack) -> std::string { json += ",\"query\":\"" + e.query + "\""; } - return api+"("+p0+"){"+cmd+"("+p1+")"+fields+"}}&variables={"+json+"}"; + json = curl::EscapeString('{'+json+'}'); + + return api+"("+p0+"){"+cmd+"("+p1+")"+fields+"}}&variables="+json; } auto apiBuildUrlDownloadInternal(const std::string& id, bool is_pack) -> std::string {