CLOUD: Fix GoogleDriveStorage to work with root folder

Now it needs another scope and uses "root" instead of "appDataFolder".
This commit is contained in:
Alexander Tkachev 2016-06-07 13:49:26 +06:00
parent d1d71afb07
commit 505d3764cb
6 changed files with 19 additions and 44 deletions

View file

@ -127,39 +127,6 @@ void CloudManager::testFeature() {
//if (storage) storage->info(nullptr, nullptr); //if (storage) storage->info(nullptr, nullptr);
GoogleDrive::GoogleDriveStorage *gd = dynamic_cast<GoogleDrive::GoogleDriveStorage *>(storage); GoogleDrive::GoogleDriveStorage *gd = dynamic_cast<GoogleDrive::GoogleDriveStorage *>(storage);
if (gd) { if (gd) {
//new folder in root: +
//gd->createDirectory("newfolder1", nullptr, nullptr);
//check it's there: +
//gd->listDirectoryById("appDataFolder", nullptr, nullptr);
//new folder in firstfolder: +
//gd->createDirectory("firstfolder/newfolder2", nullptr, nullptr);
//check it's there: +
//gd->listDirectoryById("1LWq-r1IwegkJJ0eZpswGlyjj8nu6XyUmosvxD7L0F9X3", nullptr, nullptr);
//create existing folder in firstfolder: +
//gd->createDirectory("firstfolder/subfolder", nullptr, nullptr);
//check no new folder there: +
//gd->listDirectoryById("1LWq-r1IwegkJJ0eZpswGlyjj8nu6XyUmosvxD7L0F9X3", nullptr, nullptr);
//create folder in subfolder: +
//gd->createDirectory("firstfolder/subfolder/newfolder3", nullptr, nullptr);
//check it's there: +
//gd->listDirectoryById("1OysvorQlmGl2ObMGb1c-JnjfC5yFL-Zj7AsQQhNNBnrk", nullptr, nullptr);
//one more time: +
//gd->createDirectory("firstfolder/subfolder/newfolder3/megafolder", nullptr, nullptr);
//check it's there: +
//gd->listDirectoryById("1OXWPtfNgnmR_1K7SDm2v5J923bbAWrTdVDj-zRppLZDw", nullptr, nullptr);
//gd->listDirectory("", nullptr, nullptr);
//gd->listDirectory("firstfolder", nullptr, nullptr);
gd->listDirectory("firstfolder/subfolder", nullptr, nullptr, true);
} }
//gd->resolveFileId("firstfolder/subfolder", nullptr, nullptr); //gd->resolveFileId("firstfolder/subfolder", nullptr, nullptr);
//gd->listDirectoryById("appDataFolder", nullptr, nullptr); //gd->listDirectoryById("appDataFolder", nullptr, nullptr);

View file

@ -45,8 +45,6 @@ void GoogleDriveCreateDirectoryRequest::start() {
_ignoreCallback = true; _ignoreCallback = true;
if (_workingRequest) _workingRequest->finish(); if (_workingRequest) _workingRequest->finish();
_workingRequest = nullptr; _workingRequest = nullptr;
_currentDirectory = "";
_currentDirectoryId = "appDataFolder";
_ignoreCallback = false; _ignoreCallback = false;
//find out the parent id //find out the parent id

View file

@ -37,8 +37,6 @@ class GoogleDriveCreateDirectoryRequest: public Networking::Request {
Common::String _requestedDirectoryName; Common::String _requestedDirectoryName;
GoogleDriveStorage *_storage; GoogleDriveStorage *_storage;
Storage::BoolCallback _boolCallback; Storage::BoolCallback _boolCallback;
Common::String _currentDirectory;
Common::String _currentDirectoryId;
Request *_workingRequest; Request *_workingRequest;
bool _ignoreCallback; bool _ignoreCallback;

View file

@ -55,7 +55,8 @@ void GoogleDriveListDirectoryByIdRequest::start() {
} }
void GoogleDriveListDirectoryByIdRequest::makeRequest(Common::String pageToken) { void GoogleDriveListDirectoryByIdRequest::makeRequest(Common::String pageToken) {
Common::String url = "https://www.googleapis.com/drive/v3/files?spaces=appDataFolder"; Common::String url = "https://www.googleapis.com/drive/v3/files?spaces=drive&fields=files%28id,mimeType,modifiedTime,name,size%29,nextPageToken";
//files(id,mimeType,modifiedTime,name,size),nextPageToken
if (pageToken != "") url += "&pageToken=" + pageToken; if (pageToken != "") url += "&pageToken=" + pageToken;
url += "&q=%27" + _requestedId + "%27+in+parents"; url += "&q=%27" + _requestedId + "%27+in+parents";
@ -66,6 +67,17 @@ void GoogleDriveListDirectoryByIdRequest::makeRequest(Common::String pageToken)
_workingRequest = ConnMan.addRequest(request); _workingRequest = ConnMan.addRequest(request);
} }
namespace {
uint64 atoull(Common::String s) {
uint64 result = 0;
for (uint32 i = 0; i < s.size(); ++i) {
if (s[i] < '0' || s[i] > '9') break;
result = result * 10L + (s[i] - '0');
}
return result;
}
}
void GoogleDriveListDirectoryByIdRequest::responseCallback(Networking::JsonResponse response) { void GoogleDriveListDirectoryByIdRequest::responseCallback(Networking::JsonResponse response) {
_workingRequest = nullptr; _workingRequest = nullptr;
if (_ignoreCallback) return; if (_ignoreCallback) return;
@ -100,10 +112,10 @@ void GoogleDriveListDirectoryByIdRequest::responseCallback(Networking::JsonRespo
Common::String name = item.getVal("name")->asString(); Common::String name = item.getVal("name")->asString();
bool isDirectory = (item.getVal("mimeType")->asString() == "application/vnd.google-apps.folder"); bool isDirectory = (item.getVal("mimeType")->asString() == "application/vnd.google-apps.folder");
uint32 size = 0, timestamp = 0; uint32 size = 0, timestamp = 0;
if (!isDirectory) { if (item.contains("size") && item.getVal("size")->isString())
size = item.getVal("size")->asIntegerNumber(); size = atoull(item.getVal("size")->asString());
if (item.contains("modifiedTime") && item.getVal("modifiedTime")->isString())
timestamp = ISO8601::convertToTimestamp(item.getVal("modifiedTime")->asString()); timestamp = ISO8601::convertToTimestamp(item.getVal("modifiedTime")->asString());
}
_files.push_back(StorageFile(path, name, size, timestamp, isDirectory)); _files.push_back(StorageFile(path, name, size, timestamp, isDirectory));
} }
} }

View file

@ -50,7 +50,7 @@ void GoogleDriveResolveIdRequest::start() {
if (_workingRequest) _workingRequest->finish(); if (_workingRequest) _workingRequest->finish();
_workingRequest = nullptr; _workingRequest = nullptr;
_currentDirectory = ""; _currentDirectory = "";
_currentDirectoryId = "appDataFolder"; _currentDirectoryId = "root";
_ignoreCallback = false; _ignoreCallback = false;
listNextDirectory(StorageFile(_currentDirectoryId, 0, 0, true)); listNextDirectory(StorageFile(_currentDirectoryId, 0, 0, true));

View file

@ -316,7 +316,7 @@ Networking::Request *GoogleDriveStorage::createDirectory(Common::String path, Bo
} }
if (parentPath == "") { if (parentPath == "") {
return createDirectoryWithParentId("appDataFolder", directoryName, callback, errorCallback); return createDirectoryWithParentId("root", directoryName, callback, errorCallback);
} }
return addRequest(new GoogleDriveCreateDirectoryRequest(this, parentPath, directoryName, callback, errorCallback)); return addRequest(new GoogleDriveCreateDirectoryRequest(this, parentPath, directoryName, callback, errorCallback));
@ -379,7 +379,7 @@ Common::String GoogleDriveStorage::getAuthLink() {
url += "&redirect_uri=http://localhost"; //that's for copy-pasting url += "&redirect_uri=http://localhost"; //that's for copy-pasting
//url += "&redirect_uri=http%3A%2F%2Flocalhost"; //that's "http://localhost" for automatic opening //url += "&redirect_uri=http%3A%2F%2Flocalhost"; //that's "http://localhost" for automatic opening
url += "&client_id="; url += KEY; url += "&client_id="; url += KEY;
url += "&scope=https://www.googleapis.com/auth/drive.appfolder"; //for copy-pasting url += "&scope=https://www.googleapis.com/auth/drive"; //for copy-pasting
return url; return url;
} }