Ensure Amazon is connected before serving URLs.
This commit is contained in:
parent
25ec9c65f4
commit
748d88d993
@ -10,6 +10,7 @@
|
|||||||
#include "core/logging.h"
|
#include "core/logging.h"
|
||||||
#include "core/network.h"
|
#include "core/network.h"
|
||||||
#include "core/player.h"
|
#include "core/player.h"
|
||||||
|
#include "core/waitforsignal.h"
|
||||||
#include "internet/core/oauthenticator.h"
|
#include "internet/core/oauthenticator.h"
|
||||||
#include "internet/amazon/amazonurlhandler.h"
|
#include "internet/amazon/amazonurlhandler.h"
|
||||||
#include "library/librarybackend.h"
|
#include "library/librarybackend.h"
|
||||||
@ -49,6 +50,7 @@ bool AmazonCloudDrive::has_credentials() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QUrl AmazonCloudDrive::GetStreamingUrlFromSongId(const QUrl& url) {
|
QUrl AmazonCloudDrive::GetStreamingUrlFromSongId(const QUrl& url) {
|
||||||
|
EnsureConnected(); // Access token must be up to date.
|
||||||
QUrl download_url(
|
QUrl download_url(
|
||||||
QString(kDownloadEndpoint).arg(content_url_).arg(url.path()));
|
QString(kDownloadEndpoint).arg(content_url_).arg(url.path()));
|
||||||
download_url.setFragment(QString("Bearer %1").arg(access_token_));
|
download_url.setFragment(QString("Bearer %1").arg(access_token_));
|
||||||
@ -76,6 +78,11 @@ void AmazonCloudDrive::Connect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AmazonCloudDrive::EnsureConnected() {
|
void AmazonCloudDrive::EnsureConnected() {
|
||||||
|
if (access_token_.isEmpty() ||
|
||||||
|
QDateTime::currentDateTime().secsTo(expiry_time_) < 60) {
|
||||||
|
Connect();
|
||||||
|
WaitForSignal(this, SIGNAL(Connected()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AmazonCloudDrive::ForgetCredentials() {
|
void AmazonCloudDrive::ForgetCredentials() {
|
||||||
@ -98,7 +105,6 @@ void AmazonCloudDrive::ConnectFinished(OAuthenticator* oauth) {
|
|||||||
s.setValue("refresh_token", oauth->refresh_token());
|
s.setValue("refresh_token", oauth->refresh_token());
|
||||||
|
|
||||||
access_token_ = oauth->access_token();
|
access_token_ = oauth->access_token();
|
||||||
// TODO: Amazon expiry time is only an hour so refresh this regularly.
|
|
||||||
expiry_time_ = oauth->expiry_time();
|
expiry_time_ = oauth->expiry_time();
|
||||||
|
|
||||||
FetchEndpoint();
|
FetchEndpoint();
|
||||||
@ -125,9 +131,13 @@ void AmazonCloudDrive::FetchEndpointFinished(QNetworkReply* reply) {
|
|||||||
s.beginGroup(kSettingsGroup);
|
s.beginGroup(kSettingsGroup);
|
||||||
QString checkpoint = s.value("checkpoint", "").toString();
|
QString checkpoint = s.value("checkpoint", "").toString();
|
||||||
RequestChanges(checkpoint);
|
RequestChanges(checkpoint);
|
||||||
|
|
||||||
|
// We wait until we know the endpoint URLs before emitting Connected();
|
||||||
|
emit Connected();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AmazonCloudDrive::RequestChanges(const QString& checkpoint) {
|
void AmazonCloudDrive::RequestChanges(const QString& checkpoint) {
|
||||||
|
EnsureConnected();
|
||||||
QUrl url(QString(kChangesEndpoint).arg(metadata_url_));
|
QUrl url(QString(kChangesEndpoint).arg(metadata_url_));
|
||||||
|
|
||||||
QVariantMap data;
|
QVariantMap data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user