comparison src/services/anilist.cc @ 365:f81bed4e04ac

*: megacommit that probably breaks things
author Paper <paper@paper.us.eu.org>
date Wed, 02 Oct 2024 23:06:43 -0400
parents 948955c3ba81
children
comparison
equal deleted inserted replaced
364:99c961c91809 365:f81bed4e04ac
68 "synonyms\n" \ 68 "synonyms\n" \
69 "description(asHtml: false)\n" 69 "description(asHtml: false)\n"
70 70
71 /* FIXME: why is this here */ 71 /* FIXME: why is this here */
72 72
73 static bool AccountIsValid() {
74 const auto& auth = session.config.auth.anilist;
75 return (auth.user_id && !auth.auth_token.empty());
76 }
77
78 static std::optional<nlohmann::json> SendJSONRequest(const nlohmann::json& data) { 73 static std::optional<nlohmann::json> SendJSONRequest(const nlohmann::json& data) {
79 if (!AccountIsValid()) { 74 std::vector<std::string> headers = {
80 session.SetStatusBar(Strings::Translate("AniList: Account isn't valid! (unauthorized?)"));
81 return std::nullopt;
82 }
83
84 const auto& auth = session.config.auth.anilist;
85
86 const std::vector<std::string> headers = {
87 "Authorization: Bearer " + auth.auth_token,
88 "Accept: application/json", 75 "Accept: application/json",
89 "Content-Type: application/json", 76 "Content-Type: application/json",
90 }; 77 };
78
79 if (!session.config.auth.anilist.auth_token.empty())
80 headers.push_back("Authorization: Bearer " + session.config.auth.anilist.auth_token);
91 81
92 const std::string response = Strings::ToUtf8String(HTTP::Request("https://graphql.anilist.co", headers, data.dump(), HTTP::Type::Post)); 82 const std::string response = Strings::ToUtf8String(HTTP::Request("https://graphql.anilist.co", headers, data.dump(), HTTP::Type::Post));
93 if (response.empty()) { 83 if (response.empty()) {
94 session.SetStatusBar(Strings::Translate("AniList: JSON request returned an empty result!")); 84 session.SetStatusBar(Strings::Translate("AniList: JSON request returned an empty result!"));
95 return std::nullopt; 85 return std::nullopt;