diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3ece096d..c83ce890 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,7 +54,7 @@ target_compile_definitions(${PROJECT_NAME} $<$:EVENTO_RELEASE> ${PLATFORM} LOCALE_DIR="${SOURCE_LOCALE_DIR}" - EVENTO_API_V1 + # EVENTO_API_V1 ) target_link_libraries(${PROJECT_NAME} diff --git a/src/Controller/Core/AccountManager.cc b/src/Controller/Core/AccountManager.cc index 439bcc11..d496fa72 100644 --- a/src/Controller/Core/AccountManager.cc +++ b/src/Controller/Core/AccountManager.cc @@ -68,7 +68,7 @@ void AccountManager::performLogin() { #else self.setKeychainRefreshToken(data.refreshToken); self.scheduleRenewAccessToken(); - self.expiredTime = std::chrono::system_clock::now() + std::chrono::days(7); + self._expiredTime = std::chrono::system_clock::now() + std::chrono::days(7); #endif self.setNetworkAccessToken(data.accessToken); self.setLoginState(true); @@ -147,7 +147,7 @@ void AccountManager::requestLogout() { self._userInfo = UserInfoEntity(); #ifndef EVENTO_API_V1 setKeychainRefreshToken(""); - renewAccessTokenTimer.cancel(); + _renewAccessTokenTimer.cancel(); #endif setNetworkAccessToken(""); diff --git a/src/Infrastructure/Network/Api/Evento.hh b/src/Infrastructure/Network/Api/Evento.hh index 20d4ee0b..1f4ae3fb 100644 --- a/src/Infrastructure/Network/Api/Evento.hh +++ b/src/Infrastructure/Network/Api/Evento.hh @@ -35,7 +35,11 @@ struct Evento { req.set(http::field::host, url.host()); req.set(http::field::user_agent, "SAST-Evento-Desktop/2"); if (token) // set token if exists +#ifdef EVENTO_API_V1 req.set("TOKEN", *token); +#else + req.set(http::field::authorization, std::format("Bearer {}", *token)); +#endif if (verb == http::verb::post) { req.set(http::field::content_type, MIME_FORM_URL_ENCODED); diff --git a/src/Infrastructure/Network/NetworkClient.cc b/src/Infrastructure/Network/NetworkClient.cc index e18d42cf..4817b725 100644 --- a/src/Infrastructure/Network/NetworkClient.cc +++ b/src/Infrastructure/Network/NetworkClient.cc @@ -98,7 +98,7 @@ Task> NetworkClient::loginViaSastLink(std::string code) { #else auto result = co_await this->request(http::verb::post, - endpoint("/login/link"), + endpoint("/v2/login/link"), {{"code", code}, {"type", "0"}}); if (result.isErr()) @@ -136,7 +136,7 @@ Task> NetworkClient::getUserInfo() { Task> NetworkClient::refreshAccessToken(std::string refreshToken) { auto result = co_await this->request(http::verb::post, - endpoint("/refresh-token"), + endpoint("/v2/refresh-token"), {{"refreshToken", refreshToken}}); if (result.isErr()) co_return Err(result.unwrapErr()); @@ -211,11 +211,12 @@ Task> NetworkClient::getLatestEventList( co_return Ok(eventEntityListV1ToV2(list)); #else - auto result = co_await this->request(http::verb::get, - endpoint("/v2/client/event/query", - {{"start", "now"}}), - {}, - cacheTtl); + auto result = co_await this->request( + http::verb::get, + endpoint("/v2/client/event/query", + {{"start", stdChrono2Iso8601Utc(std::chrono::system_clock::now())}}), + {}, + cacheTtl); if (result.isErr()) co_return Err(result.unwrapErr()); @@ -249,13 +250,14 @@ Task> NetworkClient::getHistoryEventList( co_return Ok(eventEntityListV1ToV2(list)); #else - auto result = co_await this->request(http::verb::get, - endpoint("/v2/client/event/query", - {{"page", std::to_string(page)}, - {"size", std::to_string(size)}, - {"end", "now"}}), - {}, - cacheTtl); + auto result = co_await this->request( + http::verb::get, + endpoint("/v2/client/event/query", + {{"page", std::to_string(page)}, + {"size", std::to_string(size)}, + {"end", stdChrono2Iso8601Utc(std::chrono::system_clock::now())}}), + {}, + cacheTtl); if (result.isErr()) co_return Err(result.unwrapErr()); diff --git a/src/Infrastructure/Utils/Tools.h b/src/Infrastructure/Utils/Tools.h index f9a8fe21..dda08812 100644 --- a/src/Infrastructure/Utils/Tools.h +++ b/src/Infrastructure/Utils/Tools.h @@ -58,6 +58,13 @@ inline time_t parseIso8601Utc(const char* date) { #endif } +inline std::string stdChrono2Iso8601Utc(std::chrono::system_clock::time_point time) { + std::stringstream ss; + auto timeT = std::chrono::system_clock::to_time_t(time); + ss << std::put_time(std::gmtime(&timeT), "%Y-%m-%dT%H:%M:%S.000Z"); + return ss.str(); +} + inline std::string firstDateTimeOfWeek() { auto now = std::chrono::system_clock::now(); auto time = std::chrono::system_clock::to_time_t(now);