Fix some issues with GalaxyConfig

Fix compile error: "conversion from ‘time_t {aka long int}’ to ‘const Json::Value’ is ambiguous"
Add checks for missing "expires_in" value in Galaxy tokens json
This commit is contained in:
Sude 2017-02-27 22:24:56 +02:00
parent 2b9c7f9273
commit d6d3d3a40e
2 changed files with 14 additions and 3 deletions

View File

@ -64,8 +64,9 @@ class GalaxyConfig
{
std::unique_lock<std::mutex> 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<std::mutex> 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;
}

View File

@ -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);