Audacity 3.2.0
Classes | Functions | Variables
cloud::audiocom::anonymous_namespace{UploadService.cpp} Namespace Reference

Classes

struct  AudiocomUploadOperation
 

Functions

std::string_view DeduceMimeType (const wxString &ext)
 
std::string GetUploadRequestPayload (const wxString &filePath, const wxString &projectName, bool isPublic)
 
std::string GetProgressPayload (uint64_t current, uint64_t total)
 
UploadFailedPayload ParseUploadFailedMessage (const std::string &payloadText)
 

Variables

const auto tempChangedSubscription
 

Function Documentation

◆ DeduceMimeType()

std::string_view cloud::audiocom::anonymous_namespace{UploadService.cpp}::DeduceMimeType ( const wxString &  ext)

Definition at line 42 of file UploadService.cpp.

43{
44 if (ext == "wv")
45 return "audio/x-wavpack";
46 else if (ext == "flac")
47 return "audio/x-flac";
48 else if (ext == "mp3")
49 return "audio/mpeg";
50 else
51 return "audio/x-wav";
52}

Referenced by GetUploadRequestPayload(), and cloud::audiocom::anonymous_namespace{UploadService.cpp}::AudiocomUploadOperation::HandleUploadPolicy().

Here is the caller graph for this function:

◆ GetProgressPayload()

std::string cloud::audiocom::anonymous_namespace{UploadService.cpp}::GetProgressPayload ( uint64_t  current,
uint64_t  total 
)

Definition at line 103 of file UploadService.cpp.

104{
105 rapidjson::Document document;
106 document.SetObject();
107
108 document.AddMember(
109 "progress", rapidjson::Value(current / static_cast<double>(total) * 100.0),
110 document.GetAllocator());
111
112 rapidjson::StringBuffer buffer;
113 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
114 document.Accept(writer);
115
116 return std::string(buffer.GetString());
117}

Referenced by cloud::audiocom::anonymous_namespace{UploadService.cpp}::AudiocomUploadOperation::HandleUploadProgress().

Here is the caller graph for this function:

◆ GetUploadRequestPayload()

std::string cloud::audiocom::anonymous_namespace{UploadService.cpp}::GetUploadRequestPayload ( const wxString &  filePath,
const wxString &  projectName,
bool  isPublic 
)

Definition at line 54 of file UploadService.cpp.

56{
57 rapidjson::Document document;
58 document.SetObject();
59
60 const wxFileName fileName(filePath);
61 const auto mimeType = DeduceMimeType(fileName.GetExt());
62
63 document.AddMember(
64 "mime",
65 rapidjson::Value(
66 mimeType.data(), mimeType.length(), document.GetAllocator()),
67 document.GetAllocator());
68
69 const auto downloadMime = GetServiceConfig().GetDownloadMime();
70
71 if (!downloadMime.empty())
72 {
73 document.AddMember(
74 "download_mime",
75 rapidjson::Value(
76 downloadMime.data(), downloadMime.length(),
77 document.GetAllocator()),
78 document.GetAllocator());
79 }
80
81 const auto name = audacity::ToUTF8(projectName.empty() ? fileName.GetFullName() : projectName);
82
83 document.AddMember(
84 "name",
85 rapidjson::Value(name.data(), name.length(), document.GetAllocator()),
86 document.GetAllocator());
87
88 document.AddMember(
89 "size",
90 rapidjson::Value(static_cast<int64_t>(fileName.GetSize().GetValue())),
91 document.GetAllocator());
92
93 document.AddMember(
94 "public", rapidjson::Value(isPublic), document.GetAllocator());
95
96 rapidjson::StringBuffer buffer;
97 rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
98 document.Accept(writer);
99
100 return std::string(buffer.GetString());
101}
const TranslatableString name
Definition: Distortion.cpp:76
std::string GetDownloadMime() const
std::string ToUTF8(const std::wstring &wstr)
std::string_view DeduceMimeType(const wxString &ext)
const ServiceConfig & GetServiceConfig()
Returns the instance of the ServiceConfig.

References DeduceMimeType(), cloud::audiocom::ServiceConfig::GetDownloadMime(), cloud::audiocom::GetServiceConfig(), name, and audacity::ToUTF8().

Referenced by cloud::audiocom::anonymous_namespace{UploadService.cpp}::AudiocomUploadOperation::InitiateUpload().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParseUploadFailedMessage()

UploadFailedPayload cloud::audiocom::anonymous_namespace{UploadService.cpp}::ParseUploadFailedMessage ( const std::string &  payloadText)

Definition at line 119 of file UploadService.cpp.

120{
121 rapidjson::StringStream stream(payloadText.c_str());
122 rapidjson::Document document;
123
124 document.ParseStream(stream);
125
126 if (!document.IsObject())
127 {
128 // This is unexpected, just return an empty object
129 assert(document.IsObject());
130 return {};
131 }
132
133 UploadFailedPayload payload;
134
135 auto readInt = [&document](const char* name) {
136 return document.HasMember(name) && document[name].IsInt() ?
137 document[name].GetInt() :
138 0;
139 };
140
141 auto readString = [&document](const char* name) -> const char*
142 {
143 return document.HasMember(name) && document[name].IsString() ?
144 document[name].GetString() :
145 "";
146 };
147
148 payload.code = readInt("code");
149 payload.status = readInt("status");
150
151 payload.name = readString("name");
152 payload.message = readString("message");
153
154 if (document.HasMember("errors") && document["errors"].IsObject())
155 {
156 for (auto& err : document["errors"].GetObject ())
157 {
158 if (!err.value.IsString())
159 continue;
160
161 payload.additionalErrors.emplace_back(
162 err.name.GetString(), err.value.GetString());
163 }
164 }
165
166 return payload;
167}

References cloud::audiocom::UploadFailedPayload::additionalErrors, cloud::audiocom::UploadFailedPayload::code, cloud::audiocom::UploadFailedPayload::message, cloud::audiocom::UploadFailedPayload::name, name, and cloud::audiocom::UploadFailedPayload::status.

Referenced by cloud::audiocom::anonymous_namespace{UploadService.cpp}::AudiocomUploadOperation::FailPromise().

Here is the caller graph for this function:

Variable Documentation

◆ tempChangedSubscription

const auto cloud::audiocom::anonymous_namespace{UploadService.cpp}::tempChangedSubscription
Initial value:
const auto tempPath = GetUploadTempPath();
if (!wxDirExists(tempPath))
return;
wxArrayString files;
wxDir::GetAllFiles(tempPath, &files, {}, wxDIR_FILES);
for (const auto& file : files)
wxRemoveFile(file);
return;
})
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
FILES_API Observer::Publisher< FilePath > & GetTempPathObserver()
wxString GetUploadTempPath()

Definition at line 641 of file UploadService.cpp.