Skip to content

Commit

Permalink
Merge pull request #4743 from crsib/new_upload_flow
Browse files Browse the repository at this point in the history
Fixes the audio.com upload flow

1. Track Title field is added.
2. After the upload is completed URL is opened in the browser immediately.
  • Loading branch information
crsib committed Jun 7, 2023
2 parents 3766de6 + 86e0d7c commit 3f3551f
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 57 deletions.
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)
{ 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
126 changes: 72 additions & 54 deletions src/cloud/audiocom/ShareAudioDialog.cpp
Expand Up @@ -240,13 +240,29 @@ void ShareAudioDialog::Populate(ShuttleGui& s)

mContinueButton = s.AddButton(XXO("C&ontinue"));
mContinueButton->Bind(wxEVT_BUTTON, [this](auto) { OnContinue(); });
mContinueButton->Enable(mIsAuthorised);
}
s.EndHorizontalLay();
}
s.EndInvisiblePanel();
}
s.EndHorizontalLay();

const auto title = mProject.GetProjectName();

if (!title.empty())
{
mInitialStatePanel.trackTitle->SetValue(title);
mInitialStatePanel.trackTitle->SetInsertionPoint(title.length());
}

mContinueButton->Enable(mIsAuthorised && mInitialStatePanel.HasValidTitle());

mInitialStatePanel.trackTitle->Bind(
wxEVT_TEXT,
[this](auto&) {
mContinueButton->Enable(
mIsAuthorised && mInitialStatePanel.HasValidTitle());
});
}

void ShareAudioDialog::OnCancel()
Expand Down Expand Up @@ -389,7 +405,7 @@ void ShareAudioDialog::StartUploadProcess()

mServices->uploadPromise = mServices->uploadService.Upload(
mFilePath,
mProject.GetProjectName(),
mInitialStatePanel.GetTrackTitle(),
false,
[this](const auto& result)
{
Expand Down Expand Up @@ -436,28 +452,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 +462,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 +471,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 Expand Up @@ -623,35 +619,43 @@ void ShareAudioDialog::InitialStatePanel::PopulateInitialStatePanel(
s.SetBorder(0);

s.AddWindow(safenew wxStaticLine { s.GetParent() }, wxEXPAND);

s.AddSpace(16);
s.StartInvisiblePanel();

s.StartInvisiblePanel(16);
{
anonInfoPanel = s.StartInvisiblePanel();
s.StartInvisiblePanel();
{
s.SetBorder(30);

AccessibleLinksFormatter privacyPolicy(XO(
"Your audio will be uploaded to our sharing service: %s,%%which requires a free account to use."));
s.AddFixedText(XO("Track Title"));
s.AddSpace(8);
trackTitle = s.AddTextBox({}, {}, 60);
trackTitle->SetName(XO("Track Title").Translation());
trackTitle->SetFocus();
trackTitle->SetMaxLength(100);
s.AddSpace(16);

anonInfoPanel = s.StartInvisiblePanel();
{
AccessibleLinksFormatter privacyPolicy(XO(
"Your audio will be uploaded to our sharing service: %s,%%which requires a free account to use."));

privacyPolicy.FormatLink(
L"%s", XO("audio.com"), "https://audio.com");
privacyPolicy.FormatLink(
L"%s", XO("audio.com"), "https://audio.com");

privacyPolicy.FormatLink(
L"%%", TranslatableString {},
AccessibleLinksFormatter::LinkClickedHandler {});
privacyPolicy.FormatLink(
L"%%", TranslatableString {},
AccessibleLinksFormatter::LinkClickedHandler {});

privacyPolicy.Populate(s);
}
s.EndInvisiblePanel();
privacyPolicy.Populate(s);
}
s.EndInvisiblePanel();

authorizedInfoPanel = s.StartInvisiblePanel();
s.StartHorizontalLay(wxEXPAND, 1);
{
s.AddSpace(30);
s.AddFixedText(XO("Press \"Continue\" to upload to audio.com"));
authorizedInfoPanel = s.StartInvisiblePanel();
s.StartHorizontalLay(wxEXPAND, 1);
{
s.AddFixedText(XO("Press \"Continue\" to upload to audio.com"));
}
s.EndHorizontalLay();
s.EndInvisiblePanel();
}
s.EndHorizontalLay();
s.EndInvisiblePanel();
}
s.EndInvisiblePanel();
Expand All @@ -675,6 +679,8 @@ void ShareAudioDialog::InitialStatePanel::UpdateUserData()
rootParent->Layout();

rootParent->Thaw();

rootParent->Refresh();
});

auto& oauthService = GetOAuthService();
Expand Down Expand Up @@ -714,9 +720,9 @@ void ShareAudioDialog::InitialStatePanel::UpdateUserData()

anonInfoPanel->Hide();
authorizedInfoPanel->Show();

if (parent.mContinueButton != nullptr)
parent.mContinueButton->Enable();
parent.mContinueButton->Enable(!trackTitle->GetValue().empty());
}

void ShareAudioDialog::InitialStatePanel::OnLinkButtonPressed()
Expand Down Expand Up @@ -755,6 +761,18 @@ void ShareAudioDialog::InitialStatePanel::SetAnonymousState()
parent.mContinueButton->Enable(false);
}

wxString ShareAudioDialog::InitialStatePanel::GetTrackTitle() const
{
wxString ret { trackTitle->GetValue() };
ret.Trim(true).Trim(false);
return ret;
}

bool ShareAudioDialog::InitialStatePanel::HasValidTitle() const
{
return !GetTrackTitle().empty();
}

void ShareAudioDialog::ProgressPanel::PopulateProgressPanel(ShuttleGui& s)
{
root = s.StartInvisiblePanel(16);
Expand Down
3 changes: 3 additions & 0 deletions src/cloud/audiocom/ShareAudioDialog.h
Expand Up @@ -79,6 +79,7 @@ class ShareAudioDialog final :
wxButton* oauthButton { nullptr };
wxPanel* anonInfoPanel { nullptr };
wxPanel* authorizedInfoPanel { nullptr };
wxTextCtrl* trackTitle { nullptr };

Observer::Subscription mUserDataChangedSubscription;

Expand All @@ -89,6 +90,8 @@ class ShareAudioDialog final :

void SetAnonymousState();

wxString GetTrackTitle() const;
bool HasValidTitle() const;
} mInitialStatePanel;

struct ProgressPanel final
Expand Down

0 comments on commit 3f3551f

Please sign in to comment.