Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes the audio.com upload flow #4743

Merged
merged 3 commits into from Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion libraries/lib-cloud-audiocom/ServiceConfig.cpp
Expand Up @@ -46,11 +46,17 @@ std::string ServiceConfig::GetAPIUrl(std::string_view apiURI) const
std::string ServiceConfig::GetFinishUploadPage(
std::string_view audioID, std::string_view token) const
{
return "http://audio.com/audacity/upload?audioId=" + std::string(audioID) +
return "https://audio.com/audacity/upload?audioId=" + std::string(audioID) +
"&token=" + std::string(token) +
"&clientId=" + std::string(GetOAuthClientID());
}

std::string ServiceConfig::GetAudioURL(
std::string_view userSlug, std::string_view audioSlug) const
{
return "https://audio.com/" + std::string(userSlug) + "/audio/" + std::string(audioSlug) + "/edit";
}

std::chrono::milliseconds ServiceConfig::GetProgressCallbackTimeout() const
{
return std::chrono::seconds(3);
Expand Down
2 changes: 2 additions & 0 deletions libraries/lib-cloud-audiocom/ServiceConfig.h
Expand Up @@ -35,6 +35,8 @@ class CLOUD_AUDIOCOM_API ServiceConfig final
std::string GetAPIUrl(std::string_view apiURI) const;
//! Helper to construct the page URL for the anonymous upload last stage
std::string GetFinishUploadPage(std::string_view audioID, std::string_view token) const;
//! Helper to construct the page URL for the authorised upload
std::string GetAudioURL(std::string_view userSlug, std::string_view audioSlug) const;
//! Timeout between progress callbacks
std::chrono::milliseconds GetProgressCallbackTimeout() const;
//! Preferred audio format
Expand Down
11 changes: 9 additions & 2 deletions libraries/lib-cloud-audiocom/UploadService.cpp
Expand Up @@ -206,6 +206,7 @@ struct AudiocomUploadOperation final :

std::string mAudioID;
std::string mUploadToken;
std::string mUserName;

std::string mAudioSlug;

Expand Down Expand Up @@ -264,10 +265,14 @@ struct AudiocomUploadOperation final :

if (mCompletedCallback)
{
const auto uploadURL =
mAuthToken.empty() ?
mServiceConfig.GetFinishUploadPage(mAudioID, mUploadToken) :
mServiceConfig.GetAudioURL(mUserName, mAudioSlug);

mCompletedCallback(
{ UploadOperationCompleted::Result::Success,
UploadSuccessfulPayload { mAudioID, mAudioSlug } });
UploadSuccessfulPayload { mAudioID, mAudioSlug, mUploadToken, uploadURL } });
}

mProgressCallback = {};
Expand Down Expand Up @@ -395,6 +400,8 @@ struct AudiocomUploadOperation final :

if (extra.HasMember("token"))
mUploadToken = extra["token"].GetString();

mUserName = extra["audio"]["username"].GetString();
}

const auto encType = document.HasMember("enctype") ?
Expand Down Expand Up @@ -579,7 +586,7 @@ UploadOperationHandle UploadService::Upload(
mServiceConfig, fileName, projectName, isPublic,
std::move(completedCallback), std::move(progressCallback));

mOAuthService.ValidateAuth([operation](std::string_view authToken)
mOAuthService.ValidateAuth([operation, this](std::string_view authToken)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't used

{ operation->InitiateUpload(authToken); });

return UploadOperationHandle { operation };
Expand Down
4 changes: 4 additions & 0 deletions libraries/lib-cloud-audiocom/UploadService.h
Expand Up @@ -43,6 +43,10 @@ struct CLOUD_AUDIOCOM_API UploadSuccessfulPayload final
std::string audioId;
//! "Slug" to be used for shareable URL construction
std::string audioSlug;
//! Upload token, if any
std::string uploadToken;
//! URL to the uploaded audio
std::string audioUrl;
};

//! Message that is sent when upload is finished.
Expand Down
36 changes: 8 additions & 28 deletions src/cloud/audiocom/ShareAudioDialog.cpp
Expand Up @@ -436,28 +436,8 @@ void ShareAudioDialog::StartUploadProcess()
void ShareAudioDialog::HandleUploadSucceeded(
const UploadSuccessfulPayload& payload)
{
mProgressPanel.timePanel->Hide();
mProgressPanel.title->SetLabel(XO("Upload complete!").Translation());
mProgressPanel.info->Show();

mProgressPanel.info->SetLabel(
"By pressing continue, you will be taken to audio.com and given a shareable link.");
mProgressPanel.info->Wrap(mProgressPanel.root->GetSize().GetWidth());

mContinueAction = [this, slug = std::string(payload.audioSlug)]()
{
EndModal(wxID_CLOSE);
auto url = wxString::Format(
"https://audio.com/%s/%s/edit", GetUserService().GetUserSlug(),
audacity::ToWXString(slug));

OpenInDefaultBrowser(url);
};

mContinueButton->Show();

Layout();
Fit();
EndModal(wxID_CLOSE);
OpenInDefaultBrowser(wxString { payload.audioUrl });
}

void ShareAudioDialog::HandleUploadFailed(const UploadFailedPayload& payload)
Expand All @@ -466,12 +446,7 @@ void ShareAudioDialog::HandleUploadFailed(const UploadFailedPayload& payload)

TranslatableString message;

if (payload.status == 401)
{
message = XO(
"We are unable to upload this file. Please try again and make sure to link to your audio.com account before uploading.");
}
else
if (!payload.message.empty())
{
auto details = payload.message;

Expand All @@ -480,6 +455,11 @@ void ShareAudioDialog::HandleUploadFailed(const UploadFailedPayload& payload)

message = XO("Error: %s").Format(details);
}
else
{
message = XO(
"We are unable to upload this file. Please try again and make sure to link to your audio.com account before uploading.");
}

BasicUI::ShowErrorDialog(
{}, XO("Upload error"),
Expand Down