summaryrefslogtreecommitdiff
path: root/plugins/Dropbox/src/dropbox_commands.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Dropbox/src/dropbox_commands.cpp')
-rw-r--r--plugins/Dropbox/src/dropbox_commands.cpp70
1 files changed, 58 insertions, 12 deletions
diff --git a/plugins/Dropbox/src/dropbox_commands.cpp b/plugins/Dropbox/src/dropbox_commands.cpp
index b3bfc41da4..10efb39d44 100644
--- a/plugins/Dropbox/src/dropbox_commands.cpp
+++ b/plugins/Dropbox/src/dropbox_commands.cpp
@@ -6,17 +6,19 @@ void CDropbox::CommandHelp(void *arg)
CMStringA help = (char*)T2Utf(TranslateT("Dropbox supports the following commands:"));
help += "\n";
- help += "\"/list [dir]\" \t- "; help += T2Utf(TranslateT("shows all files in folder \"path\" (\"path\" is relative from root folder)"));
+ help += "\"/list [path]\" \t- "; help += T2Utf(TranslateT("shows all files in folder \"path\" (\"path\" is relative from root and can be omitted for root folder)"));
help += "\n";
help += "\"/share <path>\" \t- "; help += T2Utf(TranslateT("returns download link for file or folder with specified path (\"path\" is relative from root folder)"));
help += "\n";
+ help += "\"/search <query>\" \t- "; help += T2Utf(TranslateT("searches for file or folder matched by query (\"query\" is split on spaces into multiple tokens)"));
+ help += "\n";
help += "\"/delete <path>\" \t- "; help += T2Utf(TranslateT("deletes file or folder with specified path (\"path\" is relative from root folder)"));
ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)help.GetBuffer());
}
-void CDropbox::CommandContent(void *arg)
+void CDropbox::CommandList(void *arg)
{
CommandParam *param = (CommandParam*)arg;
@@ -46,17 +48,16 @@ void CDropbox::CommandContent(void *arg)
}
CMStringA message;
- 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;
+ JSONNode entries = root.at("entries").as_array();
+ if (entries.empty())
+ message.AppendFormat("\"%s\" %s", path, T2Utf(TranslateT("is empty")));
+ else
+ {
+ for (size_t i = 0; i < entries.size(); i++) {
+ JSONNode entry = entries[i];
+ CMStringA subName(entry.at("path_lower").as_string().c_str());
+ message.AppendFormat("%s\n", (subName[0] == '/') ? subName.Mid(1) : subName);
}
-
- 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);
@@ -98,6 +99,51 @@ void CDropbox::CommandShare(void *arg)
CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)link.GetBuffer());
}
+void CDropbox::CommandSearch(void *arg)
+{
+ CommandParam *param = (CommandParam*)arg;
+
+ char *query = (char*)param->data;
+ if (query == NULL) {
+ CMStringA error(FORMAT, T2Utf(TranslateT("\"%s\" command has invalid parameter.\nUse \"/help\" for more info.")), "/search");
+ 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"));
+ //bool useShortUrl = db_get_b(NULL, MODULE, "UseSortLinks", 1) > 0;
+ SearchRequest request(token, query);
+ 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;
+ }
+
+ JSONNode root = JSONNode::parse(response->pData);
+ if (root.empty()) {
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, param->hProcess, 0);
+ return;
+ }
+
+ CMStringA message;
+ JSONNode matches = root.at("matches").as_array();
+ if (matches.empty())
+ message.AppendFormat("\"%s\" %s", query, T2Utf(TranslateT("is not found")));
+ else
+ {
+ for (size_t i = 0; i < matches.size(); i++) {
+ JSONNode metadata = matches[i].at("metadata").as_node();
+ message.AppendFormat("%s\n", metadata.at("path_lower").as_string().c_str());
+ }
+ }
+
+ ProtoBroadcastAck(MODULE, param->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, param->hProcess, 0);
+ CallContactService(param->instance->GetDefaultContact(), PSR_MESSAGE, 0, (LPARAM)message.GetBuffer());
+}
+
void CDropbox::CommandDelete(void *arg)
{
CommandParam *param = (CommandParam*)arg;