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 <functional>
14#include <memory>
15#include <utility>
16#include <variant>
17#include <vector>
18
19#include <wx/string.h>
20
21namespace cloud::audiocom
22{
23class ServiceConfig;
24class OAuthService;
25
27struct CLOUD_AUDIOCOM_API UploadFailedPayload final
28{
29 int32_t code {};
30 int32_t status {};
31
32 std::string name;
33 std::string message;
34
35 using AdditionalError = std::pair<std::string, std::string>;
36 std::vector<AdditionalError> additionalErrors;
37};
38
40struct CLOUD_AUDIOCOM_API UploadSuccessfulPayload final
41{
43 std::string audioId;
45 std::string audioSlug;
47 std::string uploadToken;
49 std::string audioUrl;
50};
51
54struct CLOUD_AUDIOCOM_API UploadOperationCompleted final
55{
57 enum class Result
58 {
60 Success,
62 Aborted,
64 FileNotFound,
66 Unauthorized,
68 InvalidData,
70 UnexpectedResponse,
72 UploadFailed
73 };
74
77
78 using Payload = std::variant<
79 std::monostate,
82 >;
83
86};
87
89class CLOUD_AUDIOCOM_API UploadOperation
90{
91public:
93
95 virtual bool IsCompleted() = 0;
97 virtual void Abort() = 0;
100 virtual void DiscardResult() = 0;
101};
102
104class CLOUD_AUDIOCOM_API UploadOperationHandle final
105{
106public:
108 explicit UploadOperationHandle(std::shared_ptr<UploadOperation> operation);
109
114
116
117 explicit operator bool() const noexcept;
118
119 UploadOperation* operator->() const noexcept;
120
121private:
122 std::shared_ptr<UploadOperation> mOperation {};
123};
124
126class CLOUD_AUDIOCOM_API UploadService final
127{
128public:
129 UploadService(const ServiceConfig& config, OAuthService& service);
130
132 std::function<void(const UploadOperationCompleted&)>;
133
134 using ProgressCallback = std::function<void(uint64_t current, uint64_t total)>;
135
137 /*
138 Both callbacks are invoked from the network thread.
139
140 If projectName is empty, the name for the uploaded file is deduced from the fileName.
141 */
143 const wxString& fileName, const wxString& projectName, bool isPublic,
144 CompletedCallback completedCallback, ProgressCallback progressCallback);
145
146private:
149};
150
151CLOUD_AUDIOCOM_API wxString GetUploadTempPath();
152} // namespace cloud::audiocom
Service responsible for OAuth authentication against the audio.com service.
Definition: OAuthService.h:38
Configuration for the audio.com.
Definition: ServiceConfig.h:23
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:90
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
const ServiceConfig & mServiceConfig
std::function< void(const UploadOperationCompleted &)> CompletedCallback
wxString GetUploadTempPath()
STL namespace.
This structure represents an upload error as returned by the server.
Definition: UploadService.h:28
std::vector< AdditionalError > additionalErrors
Definition: UploadService.h:36
std::pair< std::string, std::string > AdditionalError
Definition: UploadService.h:35
std::variant< std::monostate, UploadSuccessfulPayload, UploadFailedPayload > Payload
Definition: UploadService.h:82
This structure represents the payload associated with successful upload.
Definition: UploadService.h:41
std::string audioSlug
"Slug" to be used for shareable URL construction
Definition: UploadService.h:45
std::string audioId
ID of the uploaded audio.
Definition: UploadService.h:43
std::string audioUrl
URL to the uploaded audio.
Definition: UploadService.h:49
std::string uploadToken
Upload token, if any.
Definition: UploadService.h:47