refactor: Implement HTTP client with proxy support (#2146)
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
#include "api_service.hpp"
|
||||
|
||||
#include "http_client/http_client.hpp"
|
||||
#include "pointers.hpp"
|
||||
#include "services/creator_storage/creator_storage_service.hpp"
|
||||
|
||||
|
||||
namespace big
|
||||
{
|
||||
|
||||
@ -18,8 +20,7 @@ namespace big
|
||||
|
||||
bool api_service::get_rid_from_username(std::string_view username, uint64_t& result)
|
||||
{
|
||||
cpr::Response response = cpr::Post(cpr::Url{"https://scui.rockstargames.com/api/friend/accountsearch"}, cpr::Header{{"Authorization", AUTHORIZATION_TICKET}, {"X-Requested-With", "XMLHttpRequest"}}, cpr::Body{{std::format("searchNickname={}", username)}});
|
||||
|
||||
const auto response = g_http_client.post("https://scui.rockstargames.com/api/friend/accountsearch", {{"Authorization", AUTHORIZATION_TICKET}, {"X-Requested-With", "XMLHttpRequest"}}, {std::format("searchNickname={}", username)});
|
||||
if (response.status_code == 200)
|
||||
{
|
||||
try
|
||||
@ -43,8 +44,7 @@ namespace big
|
||||
|
||||
bool api_service::get_username_from_rid(uint64_t rid, std::string& result)
|
||||
{
|
||||
cpr::Response response = cpr::Post(cpr::Url{"https://scui.rockstargames.com/api/friend/getprofile"}, cpr::Header{{"Authorization", AUTHORIZATION_TICKET}, {"X-Requested-With", "XMLHttpRequest"}, {"Content-Type", "application/json"}}, cpr::Body{{std::format(R"({{"RockstarId":"{}"}})", rid)}});
|
||||
|
||||
const auto response = g_http_client.post("https://scui.rockstargames.com/api/friend/getprofile", {{"Authorization", AUTHORIZATION_TICKET}, {"X-Requested-With", "XMLHttpRequest"}, {"Content-Type", "application/json"}}, std::format(R"({{"RockstarId":"{}"}})", rid));
|
||||
if (response.status_code == 200)
|
||||
{
|
||||
try
|
||||
@ -65,16 +65,16 @@ namespace big
|
||||
// Ratelimit: 10 per Minute, if exceeded than 5 min cooldown
|
||||
bool api_service::send_socialclub_message(uint64_t rid, std::string_view message)
|
||||
{
|
||||
cpr::Response response = cpr::Post(cpr::Url{"https://scui.rockstargames.com/api/messaging/sendmessage"}, cpr::Header{{"Authorization", AUTHORIZATION_TICKET}, {"X-Requested-With", "XMLHttpRequest"}, {"Content-Type", "application/json"}}, cpr::Body{{std::format(R"({{"env":"prod","title":"gta5","version":11,"recipientRockstarId":"{}","messageText":"{}"}})", rid, message)}});
|
||||
const auto response = g_http_client.post("https://scui.rockstargames.com/api/messaging/sendmessage", {{"Authorization", AUTHORIZATION_TICKET}, {"X-Requested-With", "XMLHttpRequest"}, {"Content-Type", "application/json"}}, {std::format(R"({{"env":"prod","title":"gta5","version":11,"recipientRockstarId":"{}","messageText":"{}"}})", rid, message)});
|
||||
|
||||
return response.status_code == 200;
|
||||
}
|
||||
|
||||
bool api_service::get_job_details(std::string_view content_id, nlohmann::json& result)
|
||||
{
|
||||
cpr::Response response = cpr::Get(cpr::Url{"https://scapi.rockstargames.com/ugc/mission/details"},
|
||||
cpr::Header{{"X-AMC", "true"}, {"X-Requested-With", "XMLHttpRequest"}},
|
||||
cpr::Parameters{{"title", "gtav"}, {"contentId", content_id.data()}});
|
||||
const auto response = g_http_client.get("https://scapi.rockstargames.com/ugc/mission/details",
|
||||
{{"X-AMC", "true"}, {"X-Requested-With", "XMLHttpRequest"}},
|
||||
{{"title", "gtav"}, {"contentId", content_id.data()}});
|
||||
|
||||
if (response.status_code != 200)
|
||||
return false;
|
||||
@ -92,18 +92,17 @@ namespace big
|
||||
|
||||
bool api_service::download_job_metadata(std::string_view content_id, int f1, int f0, int lang)
|
||||
{
|
||||
cpr::Response response = cpr::Get(cpr::Url{std::format("https://prod.cloud.rockstargames.com/ugc/gta5mission/{}/{}_{}_{}.json",
|
||||
const auto response = g_http_client.get(std::format("https://prod.cloud.rockstargames.com/ugc/gta5mission/{}/{}_{}_{}.json",
|
||||
content_id,
|
||||
f1,
|
||||
f0,
|
||||
languages.at(lang))});
|
||||
languages.at(lang)));
|
||||
|
||||
if (response.status_code == 200)
|
||||
{
|
||||
std::ofstream of = creator_storage_service::create_file(std::string(content_id) + ".json");
|
||||
cpr::Response r = cpr::Download(of, response.url);
|
||||
const auto of = creator_storage_service::create_file(std::string(content_id) + ".json");
|
||||
|
||||
return true;
|
||||
return g_http_client.download(response.url, of);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -21,9 +21,9 @@ namespace big
|
||||
return file_paths;
|
||||
}
|
||||
|
||||
std::ofstream creator_storage_service::create_file(std::string file)
|
||||
std::filesystem::path creator_storage_service::create_file(std::string file)
|
||||
{
|
||||
return std::ofstream(check_jobs_folder().get_file(file).get_path());
|
||||
return check_jobs_folder().get_file(file).get_path();
|
||||
}
|
||||
|
||||
void creator_storage_service::save_file(std::string_view filename)
|
||||
|
@ -8,7 +8,7 @@ namespace big
|
||||
public:
|
||||
static std::vector<std::string> list_files();
|
||||
|
||||
static std::ofstream create_file(std::string name);
|
||||
static std::filesystem::path create_file(std::string name);
|
||||
static void load_file(std::string_view file_name);
|
||||
static void save_file(std::string_view file_name);
|
||||
|
||||
|
@ -53,6 +53,7 @@ namespace big
|
||||
REACTION_SETTINGS,
|
||||
PROTECTION_SETTINGS,
|
||||
TRANSLATION_SETTINGS,
|
||||
PROXY_SETTINGS,
|
||||
DEBUG,
|
||||
|
||||
PLAYER,
|
||||
@ -155,6 +156,7 @@ namespace big
|
||||
{TAB_DECL(HOTKEY_SETTINGS), view::hotkey_settings}},
|
||||
{TAB_DECL(REACTION_SETTINGS), view::reaction_settings}},
|
||||
{TAB_DECL(PROTECTION_SETTINGS), view::protection_settings}},
|
||||
{TAB_DECL(PROXY_SETTINGS), view::proxy_settings}},
|
||||
{TAB_DECL(DEBUG), nullptr}},
|
||||
},
|
||||
},
|
||||
|
@ -2,11 +2,10 @@
|
||||
|
||||
#include "fiber_pool.hpp"
|
||||
#include "file_manager.hpp"
|
||||
#include "http_client/http_client.hpp"
|
||||
#include "pointers.hpp"
|
||||
#include "thread_pool.hpp"
|
||||
|
||||
#include <cpr/cpr.h>
|
||||
|
||||
namespace big
|
||||
{
|
||||
translation_service::translation_service() :
|
||||
@ -190,8 +189,7 @@ namespace big
|
||||
{
|
||||
if (auto it = m_remote_index.translations.find(pack_id.data()); it != m_remote_index.translations.end())
|
||||
{
|
||||
cpr::Response response = download_file("/" + it->second.file);
|
||||
|
||||
const auto response = download_file("/" + it->second.file);
|
||||
if (response.status_code == 200)
|
||||
{
|
||||
try
|
||||
@ -217,8 +215,7 @@ namespace big
|
||||
|
||||
bool translation_service::download_index()
|
||||
{
|
||||
cpr::Response response = download_file("/index.json");
|
||||
|
||||
const auto response = download_file("/index.json");
|
||||
if (response.status_code == 200)
|
||||
{
|
||||
try
|
||||
@ -276,11 +273,9 @@ namespace big
|
||||
|
||||
cpr::Response translation_service::download_file(const std::string& filename)
|
||||
{
|
||||
cpr::Response response = cpr::Get(cpr::Url{m_url + filename});
|
||||
|
||||
auto response = g_http_client.get(m_url + filename);
|
||||
if (response.status_code != 200)
|
||||
response = cpr::Get(cpr::Url{m_fallback_url + filename});
|
||||
|
||||
response = g_http_client.get(m_fallback_url + filename);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user