From ad55043322aef33c943fd493a7ae168ed47b2b48 Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Thu, 25 Oct 2018 15:35:39 +0300 Subject: [PATCH] Fixed bookmarks downloading --- map/bookmark_catalog.cpp | 3 ++- map/bookmark_catalog.hpp | 1 + map/bookmark_manager.cpp | 2 +- map/cloud.cpp | 2 +- platform/remote_file.cpp | 6 +++++- platform/remote_file.hpp | 3 ++- 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/map/bookmark_catalog.cpp b/map/bookmark_catalog.cpp index 711e0f2dac..739d27be8a 100644 --- a/map/bookmark_catalog.cpp +++ b/map/bookmark_catalog.cpp @@ -173,6 +173,7 @@ std::vector BookmarkCatalog::GetDownloadingNames() const } void BookmarkCatalog::Download(std::string const & id, std::string const & name, + std::string const & accessToken, std::function && startHandler, platform::RemoteFile::ResultHandler && finishHandler) { @@ -184,7 +185,7 @@ void BookmarkCatalog::Download(std::string const & id, std::string const & name, static uint32_t counter = 0; auto const path = base::JoinPath(GetPlatform().TmpDir(), "file" + strings::to_string(++counter)); - platform::RemoteFile remoteFile(BuildCatalogDownloadUrl(id)); + platform::RemoteFile remoteFile(BuildCatalogDownloadUrl(id), accessToken); remoteFile.DownloadAsync(path, [startHandler = std::move(startHandler)](std::string const &) { if (startHandler) diff --git a/map/bookmark_catalog.hpp b/map/bookmark_catalog.hpp index df1be52247..6b05acb05e 100644 --- a/map/bookmark_catalog.hpp +++ b/map/bookmark_catalog.hpp @@ -37,6 +37,7 @@ public: void RegisterByServerId(std::string const & id); void UnregisterByServerId(std::string const & id); void Download(std::string const & id, std::string const & name, + std::string const & accessToken, std::function && startHandler, platform::RemoteFile::ResultHandler && finishHandler); diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index 0342301a10..157adb2353 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -2119,7 +2119,7 @@ void BookmarkManager::SetCatalogHandlers(OnCatalogDownloadStartedHandler && onCa void BookmarkManager::DownloadFromCatalogAndImport(std::string const & id, std::string const & name) { - m_bookmarkCatalog.Download(id, name, [this, id]() + m_bookmarkCatalog.Download(id, name, m_user.GetAccessToken(), [this, id]() { if (m_onCatalogDownloadStarted) m_onCatalogDownloadStarted(id); diff --git a/map/cloud.cpp b/map/cloud.cpp index 6e1701111b..b56fb84817 100644 --- a/map/cloud.cpp +++ b/map/cloud.cpp @@ -1391,7 +1391,7 @@ void Cloud::DownloadingTask(std::string const & dirPath, bool useFallbackUrl, platform::RemoteFile remoteFile(useFallbackUrl ? result.m_response.m_fallbackUrl : result.m_response.m_url, - false /* allowRedirection */); + {} /* accessToken */, false /* allowRedirection */); auto const downloadResult = remoteFile.Download(filePath); if (downloadResult.m_status == platform::RemoteFile::Status::Ok) diff --git a/platform/remote_file.cpp b/platform/remote_file.cpp index a79a3ecdf1..483a5a14fb 100644 --- a/platform/remote_file.cpp +++ b/platform/remote_file.cpp @@ -14,8 +14,10 @@ namespace double constexpr kRequestTimeoutInSec = 5.0; } // namespace -RemoteFile::RemoteFile(std::string url, bool allowRedirection) +RemoteFile::RemoteFile(std::string url, std::string accessToken /* = {} */, + bool allowRedirection /* = true */) : m_url(std::move(url)) + , m_accessToken(std::move(accessToken)) , m_allowRedirection(allowRedirection) {} @@ -26,6 +28,8 @@ RemoteFile::Result RemoteFile::Download(std::string const & filePath) const platform::HttpClient request(m_url); request.SetTimeout(kRequestTimeoutInSec); + if (!m_accessToken.empty()) + request.SetRawHeader("Authorization", "Bearer " + m_accessToken); request.SetRawHeader("User-Agent", GetPlatform().GetAppUserAgent()); if (request.RunHttpRequest()) { diff --git a/platform/remote_file.hpp b/platform/remote_file.hpp index d2f3898dfe..346e5d97e0 100644 --- a/platform/remote_file.hpp +++ b/platform/remote_file.hpp @@ -36,7 +36,7 @@ public: {} }; - explicit RemoteFile(std::string url, bool allowRedirection = true); + explicit RemoteFile(std::string url, std::string accessToken = {}, bool allowRedirection = true); Result Download(std::string const & filePath) const; @@ -48,6 +48,7 @@ public: private: std::string const m_url; + std::string const m_accessToken; bool const m_allowRedirection; }; } // namespace platform