aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/cloud/onedrive/onedrivestorage.cpp45
-rw-r--r--backends/cloud/onedrive/onedrivestorage.h5
2 files changed, 44 insertions, 6 deletions
diff --git a/backends/cloud/onedrive/onedrivestorage.cpp b/backends/cloud/onedrive/onedrivestorage.cpp
index 1e9a641e8a..a16a351690 100644
--- a/backends/cloud/onedrive/onedrivestorage.cpp
+++ b/backends/cloud/onedrive/onedrivestorage.cpp
@@ -131,6 +131,40 @@ void OneDriveStorage::saveConfig(Common::String keyPrefix) {
ConfMan.set(keyPrefix + "refresh_token", _refreshToken, "cloud");
}
+void OneDriveStorage::infoInnerCallback(StorageInfoCallback outerCallback, Networking::JsonResponse response) {
+ Common::JSONValue *json = response.value;
+ if (!json) {
+ warning("NULL passed instead of JSON");
+ delete outerCallback;
+ return;
+ }
+
+ if (outerCallback) {
+ Common::JSONObject info = json->asObject();
+
+ Common::String uid, name, email;
+ uint32 quotaUsed = 0, quotaAllocated = 25 * 1024 * 1024 * 1024; // 25 GB, because I actually don't know any way to find out the real one
+
+ if (info.contains("createdBy") && info.getVal("createdBy")->isObject()) {
+ Common::JSONObject createdBy = info.getVal("createdBy")->asObject();
+ if (createdBy.contains("user") && createdBy.getVal("user")->isObject()) {
+ Common::JSONObject user = createdBy.getVal("user")->asObject();
+ uid = user.getVal("id")->asString();
+ name = user.getVal("displayName")->asString();
+ }
+ }
+
+ if (info.contains("size") && info.getVal("size")->isIntegerNumber()) {
+ quotaUsed = info.getVal("size")->asIntegerNumber();
+ }
+
+ (*outerCallback)(StorageInfoResponse(nullptr, StorageInfo(uid, name, email, quotaUsed, quotaAllocated)));
+ delete outerCallback;
+ }
+
+ delete json;
+}
+
void OneDriveStorage::printJson(Networking::JsonResponse response) {
Common::JSONValue *json = response.value;
if (!json) {
@@ -232,13 +266,14 @@ Networking::ErrorCallback OneDriveStorage::getErrorPrintingCallback() {
Networking::Request *OneDriveStorage::syncSaves(BoolCallback callback, Networking::ErrorCallback errorCallback) {
//this is not the real syncSaves() implementation
- /*
- Networking::JsonCallback innerCallback = new Common::Callback<OneDriveStorage, Networking::RequestJsonPair>(this, &OneDriveStorage::printJson);
- Networking::CurlJsonRequest *request = new OneDriveTokenRefresher(this, innerCallback, "https://api.onedrive.com/v1.0/drive/special/approot");
+ return ConnMan.addRequest(new SavesSyncRequest(this, new Common::Callback<OneDriveStorage, BoolResponse>(this, &OneDriveStorage::printBool), getErrorPrintingCallback())); //TODO
+}
+
+Networking::Request *OneDriveStorage::info(StorageInfoCallback callback, Networking::ErrorCallback errorCallback) {
+ Networking::JsonCallback innerCallback = new Common::CallbackBridge<OneDriveStorage, StorageInfoResponse, Networking::JsonResponse>(this, &OneDriveStorage::infoInnerCallback, callback);
+ Networking::CurlJsonRequest *request = new OneDriveTokenRefresher(this, innerCallback, errorCallback, "https://api.onedrive.com/v1.0/drive/special/approot");
request->addHeader("Authorization: bearer " + _token);
return ConnMan.addRequest(request);
- */
- return ConnMan.addRequest(new SavesSyncRequest(this, new Common::Callback<OneDriveStorage, BoolResponse>(this, &OneDriveStorage::printBool), getErrorPrintingCallback())); //TODO
}
Common::String OneDriveStorage::savesDirectoryPath() { return "saves/"; }
diff --git a/backends/cloud/onedrive/onedrivestorage.h b/backends/cloud/onedrive/onedrivestorage.h
index 45a8dca331..5741f8e20e 100644
--- a/backends/cloud/onedrive/onedrivestorage.h
+++ b/backends/cloud/onedrive/onedrivestorage.h
@@ -49,6 +49,9 @@ class OneDriveStorage: public Cloud::Storage {
void tokenRefreshed(BoolCallback callback, Networking::JsonResponse response);
void codeFlowComplete(BoolResponse response);
+ /** Constructs StorageInfo based on JSON response from cloud. */
+ void infoInnerCallback(StorageInfoCallback outerCallback, Networking::JsonResponse json);
+
void printJson(Networking::JsonResponse response);
void fileDownloaded(BoolResponse response);
void printFiles(FileArrayResponse response);
@@ -105,7 +108,7 @@ public:
virtual Networking::Request *touch(Common::String path, BoolCallback callback, Networking::ErrorCallback errorCallback) { return nullptr; } //TODO
/** Returns the StorageInfo struct. */
- virtual Networking::Request *info(StorageInfoCallback callback, Networking::ErrorCallback errorCallback) { return nullptr; } //TODO
+ virtual Networking::Request *info(StorageInfoCallback callback, Networking::ErrorCallback errorCallback);
/** Returns storage's saves directory path with the trailing slash. */
virtual Common::String savesDirectoryPath();