diff options
| author | Aotrix <[email protected]> | 2025-03-27 12:58:24 +0100 |
|---|---|---|
| committer | Aotrix <[email protected]> | 2025-03-27 12:58:24 +0100 |
| commit | 29832e3eccceb10b5e6a9b9de554e0a45f4f1fc9 (patch) | |
| tree | afa88d0e9139026572cb1c152f7fc4ba1594008c /src/hearthstoneAPIHandler.cpp | |
| parent | 31ab522fb80473676ff31f3434f4651a1a4ee1a3 (diff) | |
switched to std::chrono::seconds for tokens
Diffstat (limited to 'src/hearthstoneAPIHandler.cpp')
| -rw-r--r-- | src/hearthstoneAPIHandler.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/hearthstoneAPIHandler.cpp b/src/hearthstoneAPIHandler.cpp index 7db7b04..ff8aa9b 100644 --- a/src/hearthstoneAPIHandler.cpp +++ b/src/hearthstoneAPIHandler.cpp @@ -23,8 +23,8 @@ size_t HearthstoneAPIHandler::curl_callback_string_output(void *t_contents, return newLength; } -std::chrono::hours HearthstoneAPIHandler::get_current_time() { - return std::chrono::duration_cast<std::chrono::hours>( +std::chrono::seconds HearthstoneAPIHandler::get_current_time() { + return std::chrono::duration_cast<std::chrono::seconds>( std::chrono::utc_clock::now().time_since_epoch()); } @@ -64,7 +64,8 @@ void HearthstoneAPIHandler::write_new_token_info_to_file( } std::string token = extract_string_with_regex(token_info, "\"access_token\":\"(\\w+)\""); - std::chrono::hours expires_at = get_current_time() + std::chrono::hours(24); + std::chrono::seconds expires_at = + get_current_time() + std::chrono::hours(24); token_file << token << " " << expires_at.count(); } @@ -78,7 +79,7 @@ void HearthstoneAPIHandler::refresh_token_if_needed() { write_new_token_info_to_file(file_path); } else { unsigned long expire_at = std::stoull(line.substr(line.find(" ") + 1)); - if (std::chrono::duration_cast<std::chrono::hours>( + if (std::chrono::duration_cast<std::chrono::seconds>( std::chrono::utc_clock::now().time_since_epoch()) .count() >= expire_at) { write_new_token_info_to_file(file_path); |
