Audacity 3.2.0
Classes | Functions | Variables
audacity::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 audacity::cloud::audiocom::anonymous_namespace{UploadService.cpp}::DeduceMimeType ( const wxString &  ext)

Definition at line 43 of file UploadService.cpp.

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

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

Here is the caller graph for this function:

◆ GetProgressPayload()

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

Definition at line 104 of file UploadService.cpp.

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

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

Here is the caller graph for this function:

◆ GetUploadRequestPayload()

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

Definition at line 55 of file UploadService.cpp.

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

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

Referenced by audacity::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 audacity::cloud::audiocom::anonymous_namespace{UploadService.cpp}::ParseUploadFailedMessage ( const std::string &  payloadText)

Definition at line 120 of file UploadService.cpp.

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

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

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

Here is the caller graph for this function:

Variable Documentation

◆ tempChangedSubscription

const auto audacity::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()

Definition at line 649 of file UploadService.cpp.