forked from organicmaps/organicmaps
Fixed bookmarks downloading
This commit is contained in:
parent
bc0178a24b
commit
ad55043322
6 changed files with 12 additions and 5 deletions
|
@ -173,6 +173,7 @@ std::vector<std::string> BookmarkCatalog::GetDownloadingNames() const
|
|||
}
|
||||
|
||||
void BookmarkCatalog::Download(std::string const & id, std::string const & name,
|
||||
std::string const & accessToken,
|
||||
std::function<void()> && 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)
|
||||
|
|
|
@ -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<void()> && startHandler,
|
||||
platform::RemoteFile::ResultHandler && finishHandler);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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())
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue