Audacity 3.2.0
UploadService.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 UploadService.h
7
8 Dmitry Vedenko
9
10**********************************************************************/
11#pragma once
12
13#include <cstdint>
14#include <functional>
15#include <memory>
16#include <utility>
17#include <variant>
18#include <vector>
19
20#include <wx/string.h>
21
22enum class AudiocomTrace;
23
25{
26class ServiceConfig;
27class OAuthService;
28
30struct CLOUD_AUDIOCOM_API UploadFailedPayload final
31{
32 int32_t code {};
33 int32_t status {};
34
35 std::string name;
36 std::string message;
37
38 using AdditionalError = std::pair<std::string, std::string>;
39 std::vector<AdditionalError> additionalErrors;
40};
41
43struct CLOUD_AUDIOCOM_API UploadSuccessfulPayload final
44{
46 std::string audioId;
48 std::string audioSlug;
50 std::string uploadToken;
52 std::string audioUrl;
53};
54
57struct CLOUD_AUDIOCOM_API UploadOperationCompleted final
58{
60 enum class Result
61 {
63 Success,
65 Aborted,
67 FileNotFound,
69 Unauthorized,
71 InvalidData,
75 UploadFailed
76 };
77
80
81 using Payload = std::variant<
82 std::monostate,
85 >;
86
89};
90
92class CLOUD_AUDIOCOM_API UploadOperation
93{
94public:
96
98 virtual bool IsCompleted() = 0;
100 virtual void Abort() = 0;
103 virtual void DiscardResult() = 0;
104};
105
107class CLOUD_AUDIOCOM_API UploadOperationHandle final
108{
109public:
111 explicit UploadOperationHandle(std::shared_ptr<UploadOperation> operation);
112
117
119
120 explicit operator bool() const noexcept;
121
122 UploadOperation* operator->() const noexcept;
123
124private:
125 std::shared_ptr<UploadOperation> mOperation {};
126};
127
129class CLOUD_AUDIOCOM_API UploadService final
130{
131public:
132 UploadService(const ServiceConfig& config, OAuthService& service);
133
135 std::function<void(const UploadOperationCompleted&)>;
136
137 using ProgressCallback = std::function<void(uint64_t current, uint64_t total)>;
138
140 /*
141 Both callbacks are invoked from the network thread.
142
143 If projectName is empty, the name for the uploaded file is deduced from the fileName.
144 */
146 const wxString& fileName, const wxString& projectName, bool isPublic,
147 CompletedCallback completedCallback, ProgressCallback progressCallback,
149
150private:
153};
154
155CLOUD_AUDIOCOM_API wxString GetUploadTempPath();
156} // namespace audacity::cloud::audiocom
AudiocomTrace
Definition: ExportUtils.h:27
Service responsible for OAuth authentication against the audio.com service.
Definition: OAuthService.h:43
Configuration for the audio.com.
Definition: ServiceConfig.h:25
A unique_ptr like class that holds a pointer to UploadOperation.
UploadOperationHandle(UploadOperationHandle &&)=default
UploadOperationHandle & operator=(const UploadOperationHandle &)=delete
UploadOperationHandle(const UploadOperationHandle &)=delete
UploadOperationHandle & operator=(UploadOperationHandle &&)=default
Class used to track the upload operation.
Definition: UploadService.h:93
virtual bool IsCompleted()=0
Returns true if the upload is finished.
virtual void Abort()=0
Abort the upload, if running.
Service, responsible for uploading audio files to audio.com.
std::function< void(uint64_t current, uint64_t total)> ProgressCallback
std::function< void(const UploadOperationCompleted &)> CompletedCallback
STL namespace.
This structure represents an upload error as returned by the server.
Definition: UploadService.h:31
std::vector< AdditionalError > additionalErrors
Definition: UploadService.h:39
std::pair< std::string, std::string > AdditionalError
Definition: UploadService.h:38
std::variant< std::monostate, UploadSuccessfulPayload, UploadFailedPayload > Payload
Definition: UploadService.h:85
This structure represents the payload associated with successful upload.
Definition: UploadService.h:44
std::string audioId
ID of the uploaded audio.
Definition: UploadService.h:46
std::string audioUrl
URL to the uploaded audio.
Definition: UploadService.h:52
std::string uploadToken
Upload token, if any.
Definition: UploadService.h:50
std::string audioSlug
"Slug" to be used for shareable URL construction
Definition: UploadService.h:48