From 29832e3eccceb10b5e6a9b9de554e0a45f4f1fc9 Mon Sep 17 00:00:00 2001 From: Aotrix Date: Thu, 27 Mar 2025 12:58:24 +0100 Subject: switched to std::chrono::seconds for tokens --- src/hearthstoneAPIHandler.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') 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::seconds HearthstoneAPIHandler::get_current_time() { + return std::chrono::duration_cast( 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( + if (std::chrono::duration_cast( std::chrono::utc_clock::now().time_since_epoch()) .count() >= expire_at) { write_new_token_info_to_file(file_path); -- cgit v1.2.3