From 0b82b879821c7e73b86f189be747c5634c8b46b7 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 22 Feb 2016 21:12:25 +0000 Subject: Dropbox: - updated api to v2 - version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@16326 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Dropbox/src/dropbox_commands.cpp | 81 +++++++++++++++----------------- 1 file changed, 39 insertions(+), 42 deletions(-) (limited to 'plugins/Dropbox/src/dropbox_commands.cpp') diff --git a/plugins/Dropbox/src/dropbox_commands.cpp b/plugins/Dropbox/src/dropbox_commands.cpp index 19b6baeb62..76c373ae80 100644 --- a/plugins/Dropbox/src/dropbox_commands.cpp +++ b/plugins/Dropbox/src/dropbox_commands.cpp @@ -6,7 +6,7 @@ void CDropbox::CommandHelp(void *arg) CMStringA help = (char*)T2Utf(TranslateT("Dropbox supports the following commands:")); help += "\n"; - help += "\"/content [dir]\" \t- "; help += T2Utf(TranslateT("shows all files in folder \"dir\" (\"dir\" can be omitted for root folder)")); + help += "\"/list [dir]\" \t- "; help += T2Utf(TranslateT("shows all files in folder \"path\" (\"path\" is relative from root folder)")); help += "\n"; help += "\"/share \" \t- "; help += T2Utf(TranslateT("returns download link for file or folder with specified path (\"path\" is relative from root folder)")); help += "\n"; @@ -20,13 +20,17 @@ void CDropbox::CommandContent(void *arg) { CommandParam *param = (CommandParam*)arg; - char *path = (char*)param->data; - if (path == NULL) - path = ""; + CMStringA path = PreparePath((char*)param->data); + if (path.IsEmpty()) { + CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/share"); + ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); + CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer()); + + return; + } ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); - ptrA encodedPath(mir_utf8encode(path)); - GetMetadataRequest request(token, encodedPath); + ListFolderRequest request(token, path); NLHR_PTR response(request.Send(param->instance->hNetlibConnection)); if (response == NULL || response->resultCode != HTTP_STATUS_OK) { @@ -41,22 +45,17 @@ void CDropbox::CommandContent(void *arg) } CMStringA message; - bool isDir = root.at("is_dir").as_bool(); - if (!isDir) - message.AppendFormat("\"%s\" %s", encodedPath, T2Utf(TranslateT("is file"))); - else { - JSONNode content = root.at("contents").as_array(); - for (size_t i = 0; i < content.size(); i++) { - JSONNode item = content[i]; - if (item.empty()) { - if (i == 0) - message.AppendFormat("\"%s\" %s", encodedPath, T2Utf(TranslateT("is empty"))); - break; - } - - CMStringA subName(item.at("path").as_string().c_str()); - message.AppendFormat("%s\n", (subName[0] == '/') ? subName.Mid(1) : subName); + JSONNode content = root.at("entries").as_array(); + for (size_t i = 0; i < content.size(); i++) { + JSONNode item = content[i]; + if (item.empty()) { + if (i == 0) + message.AppendFormat("\"%s\" %s", path, T2Utf(TranslateT("is empty"))); + break; } + + CMStringA subName(item.at("path_lower ").as_string().c_str()); + message.AppendFormat("%s\n", (subName[0] == '/') ? subName.Mid(1) : subName); } ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); @@ -67,8 +66,8 @@ void CDropbox::CommandShare(void *arg) { CommandParam *param = (CommandParam*)arg; - char *path = (char*)param->data; - if (path == NULL) { + CMStringA path = PreparePath((char*)param->data); + if (path.IsEmpty()) { CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/share"); ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer()); @@ -77,9 +76,8 @@ void CDropbox::CommandShare(void *arg) } ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); - ptrA encodedPath(mir_utf8encode(path)); - bool useShortUrl = db_get_b(NULL, MODULE, "UseSortLinks", 1) > 0; - ShareRequest request(token, encodedPath, useShortUrl); + //bool useShortUrl = db_get_b(NULL, MODULE, "UseSortLinks", 1) > 0; + ShareRequest request(token, path); NLHR_PTR response(request.Send(param->instance->hNetlibConnection)); if (response == NULL || response->resultCode != HTTP_STATUS_OK) { @@ -102,8 +100,8 @@ void CDropbox::CommandDelete(void *arg) { CommandParam *param = (CommandParam*)arg; - char *path = (char*)param->data; - if (path == NULL) { + CMStringA path = PreparePath((char*)param->data); + if (path.IsEmpty()) { CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/delete"); ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)error.GetBuffer()); @@ -111,23 +109,22 @@ void CDropbox::CommandDelete(void *arg) return; } ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); - ptrA encodedPath(mir_utf8encode(path)); - DeleteRequest request(token, encodedPath); + DeleteRequest request(token, path); NLHR_PTR response(request.Send(param->instance->hNetlibConnection)); - if (response == NULL || response->resultCode != HTTP_STATUS_OK) { - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0); - return; - } + try + { + HandleJsonResponseError(response); - JSONNode root = JSONNode::parse(response->pData); - if (root.empty()) { - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0); + CMStringA message(FORMAT, "%s %s", path, T2Utf(TranslateT("is deleted"))); + ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); + CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer()); + } + catch (DropboxException &ex) + { + ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, (LPARAM)ex.what()); return; } - - bool isDeleted = root.at("is_deleted").as_bool(); - CMStringA message(FORMAT, "%s %s", path, !isDeleted ? T2Utf(TranslateT("is not deleted")) : T2Utf(TranslateT("is deleted"))); - ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0); - CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer()); + + ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0); } \ No newline at end of file -- cgit v1.2.3