fix type
This commit is contained in:
parent
24aa979a69
commit
dfa0774242
20
src/net.cpp
20
src/net.cpp
@ -21,7 +21,7 @@
|
|||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
// metods
|
// metods
|
||||||
enum {
|
enum metod {
|
||||||
GET,
|
GET,
|
||||||
POST,
|
POST,
|
||||||
};
|
};
|
||||||
@ -38,8 +38,8 @@ size_t WriteCallback(void *contents, size_t size, size_t nmemb,
|
|||||||
return totalSize;
|
return totalSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<std::string, int>
|
std::tuple<std::string, int> send_curl_request(std::string endpoint, metod type,
|
||||||
send_curl_request(std::string endpoint, uint8_t type, std::string req_data) {
|
std::string req_data) {
|
||||||
std::string response;
|
std::string response;
|
||||||
std::string url = baka_api_url + endpoint;
|
std::string url = baka_api_url + endpoint;
|
||||||
if (type == GET) {
|
if (type == GET) {
|
||||||
@ -121,13 +121,11 @@ void login(std::string username, std::string password) {
|
|||||||
json resp_parsed = json::parse(response);
|
json resp_parsed = json::parse(response);
|
||||||
|
|
||||||
access_token = resp_parsed["access_token"];
|
access_token = resp_parsed["access_token"];
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void refresh_access_token() {
|
void refresh_access_token() {
|
||||||
if(config.verbose) {
|
if (config.verbose) {
|
||||||
std::clog << "refreshing access token please wait...\n";
|
std::clog << "refreshing access token please wait...\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
json authfile_parsed = json::parse(SoRAuthFile(false, ""));
|
json authfile_parsed = json::parse(SoRAuthFile(false, ""));
|
||||||
@ -139,7 +137,6 @@ void refresh_access_token() {
|
|||||||
"token&refresh_token={}",
|
"token&refresh_token={}",
|
||||||
refresh_token);
|
refresh_token);
|
||||||
|
|
||||||
|
|
||||||
auto [response, http_code] = send_curl_request("api/login", POST, req_data);
|
auto [response, http_code] = send_curl_request("api/login", POST, req_data);
|
||||||
if (http_code != 200) {
|
if (http_code != 200) {
|
||||||
std::cerr << RED "[ERROR] " << RESET << http_code
|
std::cerr << RED "[ERROR] " << RESET << http_code
|
||||||
@ -162,12 +159,13 @@ void is_access_token_empty() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// supports all endpoints that only require access_token
|
// supports all endpoints that only require access_token
|
||||||
json get_data_from_endpoint(std::string &endpoint, std::string additional_data) {
|
json get_data_from_endpoint(std::string &endpoint,
|
||||||
|
std::string additional_data) {
|
||||||
is_access_token_empty();
|
is_access_token_empty();
|
||||||
access_token_refreshed:
|
access_token_refreshed:
|
||||||
std::string req_data =
|
std::string req_data =
|
||||||
std::format("Authorization=Bearer&access_token={}", access_token);
|
std::format("Authorization=Bearer&access_token={}", access_token);
|
||||||
if(!additional_data.empty()) {
|
if (!additional_data.empty()) {
|
||||||
req_data.append(std::format("&{}", additional_data));
|
req_data.append(std::format("&{}", additional_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user