aboutsummaryrefslogtreecommitdiff
path: root/backends/cloud/googledrive/googledrivestorage.cpp
diff options
context:
space:
mode:
authorAlexander Tkachev2016-06-06 20:04:13 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commitbb207ae513ef02bfaf8e76374af40419a20742fe (patch)
treece6be0e78048ede03233e62149c0040c3d07cf20 /backends/cloud/googledrive/googledrivestorage.cpp
parentf24a89e080df860f7a32a8b3c9f272c1623aedbb (diff)
downloadscummvm-rg350-bb207ae513ef02bfaf8e76374af40419a20742fe.tar.gz
scummvm-rg350-bb207ae513ef02bfaf8e76374af40419a20742fe.tar.bz2
scummvm-rg350-bb207ae513ef02bfaf8e76374af40419a20742fe.zip
CLOUD: Add GoogleDriveResolveIdRequest
GoogleDriveResolveIdRequest gets a lowercase path and searches for the specified file's id. To do that it lists path's subdirectories one by one with GoogleDriveListDirectoryByIdRequest. GoogleDriveListDirectoryByIdRequest gets a Google Drive id and lists that directory (not recursively).
Diffstat (limited to 'backends/cloud/googledrive/googledrivestorage.cpp')
-rw-r--r--backends/cloud/googledrive/googledrivestorage.cpp68
1 files changed, 66 insertions, 2 deletions
diff --git a/backends/cloud/googledrive/googledrivestorage.cpp b/backends/cloud/googledrive/googledrivestorage.cpp
index eef7f1f28d..b0c0d47ecf 100644
--- a/backends/cloud/googledrive/googledrivestorage.cpp
+++ b/backends/cloud/googledrive/googledrivestorage.cpp
@@ -31,6 +31,8 @@
#include "common/debug.h"
#include "common/json.h"
#include <curl/curl.h>
+#include "googledrivelistdirectorybyidrequest.h"
+#include "googledriveresolveidrequest.h"
namespace Cloud {
namespace GoogleDrive {
@@ -177,6 +179,25 @@ void GoogleDriveStorage::infoInnerCallback(StorageInfoCallback outerCallback, Ne
delete json;
}
+void GoogleDriveStorage::createDirectoryInnerCallback(BoolCallback outerCallback, Networking::JsonResponse response) {
+ Common::JSONValue *json = response.value;
+ if (!json) {
+ warning("NULL passed instead of JSON");
+ delete outerCallback;
+ return;
+ }
+
+ debug("%s", json->stringify(true).c_str());
+
+ if (outerCallback) {
+ Common::JSONObject info = json->asObject();
+ ///(*outerCallback)(BoolResponse(nullptr, true);
+ delete outerCallback;
+ }
+
+ delete json;
+}
+
void GoogleDriveStorage::printJson(Networking::JsonResponse response) {
Common::JSONValue *json = response.value;
if (!json) {
@@ -211,11 +232,23 @@ void GoogleDriveStorage::fileInfoCallback(Networking::NetworkReadStreamCallback
delete response.value;
}
+Networking::Request *GoogleDriveStorage::resolveFileId(Common::String path, UploadCallback callback, Networking::ErrorCallback errorCallback) {
+ if (!errorCallback) errorCallback = getErrorPrintingCallback();
+ if (!callback) callback = new Common::Callback<GoogleDriveStorage, UploadResponse>(this, &GoogleDriveStorage::printFile);
+ return addRequest(new GoogleDriveResolveIdRequest(this, path, callback, errorCallback));
+}
+
Networking::Request *GoogleDriveStorage::listDirectory(Common::String path, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback, bool recursive) {
//return addRequest(new GoogleDriveListDirectoryRequest(this, path, callback, errorCallback, recursive));
return nullptr; //TODO
}
+Networking::Request *GoogleDriveStorage::listDirectoryById(Common::String id, ListDirectoryCallback callback, Networking::ErrorCallback errorCallback) {
+ if (!errorCallback) errorCallback = getErrorPrintingCallback();
+ if (!callback) callback = new Common::Callback<GoogleDriveStorage, FileArrayResponse>(this, &GoogleDriveStorage::printFiles);
+ return addRequest(new GoogleDriveListDirectoryByIdRequest(this, id, callback, errorCallback));
+}
+
Networking::Request *GoogleDriveStorage::upload(Common::String path, Common::SeekableReadStream *contents, UploadCallback callback, Networking::ErrorCallback errorCallback) {
//return addRequest(new GoogleDriveUploadRequest(this, path, contents, callback, errorCallback));
return nullptr; //TODO
@@ -240,8 +273,11 @@ void GoogleDriveStorage::fileDownloaded(BoolResponse response) {
void GoogleDriveStorage::printFiles(FileArrayResponse response) {
debug("files:");
Common::Array<StorageFile> &files = response.value;
- for (uint32 i = 0; i < files.size(); ++i)
+ for (uint32 i = 0; i < files.size(); ++i) {
+ debug("\t%s%s", files[i].name().c_str(), files[i].isDirectory() ? " (directory)" : "");
debug("\t%s", files[i].path().c_str());
+ debug("");
+ }
}
void GoogleDriveStorage::printBool(BoolResponse response) {
@@ -250,7 +286,8 @@ void GoogleDriveStorage::printBool(BoolResponse response) {
void GoogleDriveStorage::printFile(UploadResponse response) {
debug("\nuploaded file info:");
- debug("\tpath: %s", response.value.path().c_str());
+ debug("\tid: %s", response.value.path().c_str());
+ debug("\tname: %s", response.value.name().c_str());
debug("\tsize: %u", response.value.size());
debug("\ttimestamp: %u", response.value.timestamp());
}
@@ -268,6 +305,33 @@ Networking::Request *GoogleDriveStorage::createDirectory(Common::String path, Bo
return nullptr; //TODO
}
+Networking::Request *GoogleDriveStorage::createDirectoryWithParentId(Common::String parentId, Common::String name, BoolCallback callback, Networking::ErrorCallback errorCallback) {
+ if (!errorCallback) errorCallback = getErrorPrintingCallback();
+ //return addRequest(new GoogleDriveCreateDirectoryRequest(this, path, callback, errorCallback));
+ Common::String url = "https://www.googleapis.com/drive/v3/files";
+ //Networking::JsonCallback callback = new Common::Callback<GoogleDriveListDirectoryByIdRequest, Networking::JsonResponse>(this, &GoogleDriveListDirectoryByIdRequest::responseCallback);
+ //Networking::ErrorCallback failureCallback = new Common::Callback<GoogleDriveListDirectoryByIdRequest, Networking::ErrorResponse>(this, &GoogleDriveListDirectoryByIdRequest::errorCallback);
+ Networking::JsonCallback innerCallback = new Common::CallbackBridge<GoogleDriveStorage, BoolResponse, Networking::JsonResponse>(this, &GoogleDriveStorage::createDirectoryInnerCallback, callback);
+ Networking::CurlJsonRequest *request = new GoogleDriveTokenRefresher(this, innerCallback, errorCallback, url.c_str());
+ request->addHeader("Authorization: Bearer " + accessToken());
+ request->addHeader("Content-Type: application/json");
+
+ Common::JSONArray parentsArray;
+ parentsArray.push_back(new Common::JSONValue(parentId));
+
+ Common::JSONObject jsonRequestParameters;
+ jsonRequestParameters.setVal("mimeType", new Common::JSONValue("application/vnd.google-apps.folder"));
+ jsonRequestParameters.setVal("name", new Common::JSONValue(name));
+ jsonRequestParameters.setVal("parents", new Common::JSONValue(parentsArray));
+ //jsonRequestParameters.setVal("include_deleted", new Common::JSONValue(false));
+
+ Common::JSONValue value(jsonRequestParameters);
+ request->addPostField(Common::JSON::stringify(&value));
+
+ return addRequest(request);
+ return nullptr; //TODO
+}
+
Networking::Request *GoogleDriveStorage::info(StorageInfoCallback callback, Networking::ErrorCallback errorCallback) {
if (!callback) callback = new Common::Callback<GoogleDriveStorage, StorageInfoResponse>(this, &GoogleDriveStorage::printInfo);
Networking::JsonCallback innerCallback = new Common::CallbackBridge<GoogleDriveStorage, StorageInfoResponse, Networking::JsonResponse>(this, &GoogleDriveStorage::infoInnerCallback, callback);