CLOUD: Add ConnMan::urlEncode()
Tried to use it everywhere I should've use it.
This commit is contained in:
parent
c99b24c16d
commit
6a93e8dd09
8 changed files with 23 additions and 8 deletions
|
@ -234,7 +234,7 @@ Networking::Request *GoogleDriveStorage::streamFile(Common::String path, Network
|
|||
|
||||
Networking::Request *GoogleDriveStorage::streamFileById(Common::String id, Networking::NetworkReadStreamCallback callback, Networking::ErrorCallback errorCallback) {
|
||||
if (callback) {
|
||||
Common::String url = "https://www.googleapis.com/drive/v3/files/" + id + "?alt=media";
|
||||
Common::String url = "https://www.googleapis.com/drive/v3/files/" + ConnMan.urlEncode(id) + "?alt=media";
|
||||
Common::String header = "Authorization: Bearer " + _token;
|
||||
curl_slist *headersList = curl_slist_append(nullptr, header.c_str());
|
||||
Networking::NetworkReadStream *stream = new Networking::NetworkReadStream(url.c_str(), headersList, "");
|
||||
|
|
|
@ -108,7 +108,7 @@ void GoogleDriveUploadRequest::startUpload() {
|
|||
}
|
||||
|
||||
Common::String url = "https://www.googleapis.com/upload/drive/v3/files";
|
||||
if (_resolvedId != "") url += "/" + _resolvedId;
|
||||
if (_resolvedId != "") url += "/" + ConnMan.urlEncode(_resolvedId);
|
||||
url += "?uploadType=resumable&fields=id,mimeType,modifiedTime,name,size";
|
||||
Networking::JsonCallback callback = new Common::Callback<GoogleDriveUploadRequest, Networking::JsonResponse>(this, &GoogleDriveUploadRequest::startUploadCallback);
|
||||
Networking::ErrorCallback failureCallback = new Common::Callback<GoogleDriveUploadRequest, Networking::ErrorResponse>(this, &GoogleDriveUploadRequest::startUploadErrorCallback);
|
||||
|
|
|
@ -63,7 +63,7 @@ void OneDriveCreateDirectoryRequest::start() {
|
|||
}
|
||||
|
||||
Common::String url = "https://api.onedrive.com/v1.0/drive/special/approot";
|
||||
if (parent != "") url += ":/" + parent + ":";
|
||||
if (parent != "") url += ":/" + ConnMan.urlEncode(parent) + ":";
|
||||
url += "/children";
|
||||
Networking::JsonCallback innerCallback = new Common::Callback<OneDriveCreateDirectoryRequest, Networking::JsonResponse>(this, &OneDriveCreateDirectoryRequest::responseCallback);
|
||||
Networking::ErrorCallback errorCallback = new Common::Callback<OneDriveCreateDirectoryRequest, Networking::ErrorResponse>(this, &OneDriveCreateDirectoryRequest::errorCallback);
|
||||
|
|
|
@ -70,8 +70,9 @@ void OneDriveListDirectoryRequest::listNextDirectory() {
|
|||
if (_currentDirectory != "" && _currentDirectory.lastChar() != '/' && _currentDirectory.lastChar() != '\\')
|
||||
_currentDirectory += '/';
|
||||
|
||||
Common::String url = "https://api.onedrive.com/v1.0/drive/special/approot:/" + _currentDirectory;
|
||||
url.deleteLastChar();
|
||||
Common::String dir = _currentDirectory;
|
||||
dir.deleteLastChar();
|
||||
Common::String url = "https://api.onedrive.com/v1.0/drive/special/approot:/" + ConnMan.urlEncode(dir);
|
||||
url += ":/children";
|
||||
makeRequest(url);
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ Networking::Request *OneDriveStorage::upload(Common::String path, Common::Seekab
|
|||
}
|
||||
|
||||
Networking::Request *OneDriveStorage::streamFileById(Common::String path, Networking::NetworkReadStreamCallback outerCallback, Networking::ErrorCallback errorCallback) {
|
||||
Common::String url = "https://api.onedrive.com/v1.0/drive/special/approot:/" + path;
|
||||
Common::String url = "https://api.onedrive.com/v1.0/drive/special/approot:/" + ConnMan.urlEncode(path);
|
||||
Networking::JsonCallback innerCallback = new Common::CallbackBridge<OneDriveStorage, Networking::NetworkReadStreamResponse, Networking::JsonResponse>(this, &OneDriveStorage::fileInfoCallback, outerCallback);
|
||||
Networking::CurlJsonRequest *request = new OneDriveTokenRefresher(this, innerCallback, errorCallback, url.c_str());
|
||||
request->addHeader("Authorization: Bearer " + _token);
|
||||
|
|
|
@ -63,7 +63,7 @@ void OneDriveUploadRequest::uploadNextPart() {
|
|||
const uint32 UPLOAD_PER_ONE_REQUEST = 10 * 1024 * 1024;
|
||||
|
||||
if (_uploadUrl == "" && _contentsStream->size() > UPLOAD_PER_ONE_REQUEST) {
|
||||
Common::String url = "https://api.onedrive.com/v1.0/drive/special/approot:/"+_savePath+":/upload.createSession"; //folder must exist
|
||||
Common::String url = "https://api.onedrive.com/v1.0/drive/special/approot:/"+ConnMan.urlEncode(_savePath)+":/upload.createSession"; //folder must exist
|
||||
Networking::JsonCallback callback = new Common::Callback<OneDriveUploadRequest, Networking::JsonResponse>(this, &OneDriveUploadRequest::partUploadedCallback);
|
||||
Networking::ErrorCallback failureCallback = new Common::Callback<OneDriveUploadRequest, Networking::ErrorResponse>(this, &OneDriveUploadRequest::partUploadedErrorCallback);
|
||||
Networking::CurlJsonRequest *request = new OneDriveTokenRefresher(_storage, callback, failureCallback, url.c_str());
|
||||
|
@ -75,7 +75,7 @@ void OneDriveUploadRequest::uploadNextPart() {
|
|||
|
||||
Common::String url;
|
||||
if (_uploadUrl == "") {
|
||||
url = "https://api.onedrive.com/v1.0/drive/special/approot:/"+_savePath+":/content";
|
||||
url = "https://api.onedrive.com/v1.0/drive/special/approot:/"+ConnMan.urlEncode(_savePath)+":/content";
|
||||
} else {
|
||||
url = _uploadUrl;
|
||||
}
|
||||
|
|
|
@ -78,6 +78,17 @@ void ConnectionManager::showCloudDisabledIcon() {
|
|||
startTimer();
|
||||
}
|
||||
|
||||
Common::String ConnectionManager::urlEncode(Common::String s) {
|
||||
if (!_multi) return "";
|
||||
char *output = curl_easy_escape(_multi, s.c_str(), s.size());
|
||||
if (output) {
|
||||
Common::String result = output;
|
||||
curl_free(output);
|
||||
return result;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
//private goes here:
|
||||
|
||||
void connectionsThread(void *ignored) {
|
||||
|
|
|
@ -117,6 +117,9 @@ public:
|
|||
|
||||
/** Shows a "cloud disabled" icon for a three seconds. */
|
||||
void showCloudDisabledIcon();
|
||||
|
||||
/** Return URL-encoded version of given string. */
|
||||
Common::String urlEncode(Common::String s);
|
||||
};
|
||||
|
||||
/** Shortcut for accessing the connection manager. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue