diff --git a/include/config.h b/include/config.h index ef66e29..a31573f 100644 --- a/include/config.h +++ b/include/config.h @@ -64,8 +64,9 @@ class GalaxyConfig { std::unique_lock lock(m); bool bExpired = false; + intmax_t time_now = time(NULL); if (this->token_json.isMember("expires_at")) - bExpired = (time(NULL) > this->token_json["expires_at"].asUInt()); + bExpired = (time_now > this->token_json["expires_at"].asLargestInt()); return bExpired; } @@ -91,7 +92,16 @@ class GalaxyConfig { std::unique_lock lock(m); if (!json.isMember("expires_at")) - json["expires_at"] = json["expires_in"].asUInt() + time(NULL); + { + intmax_t time_now = time(NULL); + Json::Value::LargestInt expires_in = 3600; + if (json.isMember("expires_in")) + if (!json["expires_in"].isNull()) + expires_in = json["expires_in"].asLargestInt(); + + Json::Value::LargestInt expires_at = time_now + expires_in; + json["expires_at"] = expires_at; + } this->token_json = json; } diff --git a/src/downloader.cpp b/src/downloader.cpp index 0dfbfbe..05bac41 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -127,7 +127,8 @@ Downloader::Downloader() if (!json.isMember("expires_at")) { std::time_t last_modified = boost::filesystem::last_write_time(Globals::galaxyConf.getFilepath()); - json["expires_at"] = json["expires_in"].asUInt() + last_modified; + Json::Value::LargestInt expires_in = json["expires_in"].asLargestInt(); + json["expires_at"] = expires_in + last_modified; } Globals::galaxyConf.setJSON(json);