summaryrefslogtreecommitdiff
path: root/plugins/Dropbox/src/dropbox_transfers.cpp
diff options
context:
space:
mode:
authorAlexander Lantsev <aunsane@gmail.com>2014-02-20 17:33:44 +0000
committerAlexander Lantsev <aunsane@gmail.com>2014-02-20 17:33:44 +0000
commitb9567416b251f589ba5ac4ed1dadc644e79d6912 (patch)
tree4e1a9e2a3a926be13cc463a19a4a685c0bfdb24f /plugins/Dropbox/src/dropbox_transfers.cpp
parent4c6a62618e1e03f97d0f194a37316a97c6ea5062 (diff)
Dropbox: download links will be created only for root files and folders
git-svn-id: http://svn.miranda-ng.org/main/trunk@8193 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Dropbox/src/dropbox_transfers.cpp')
-rw-r--r--plugins/Dropbox/src/dropbox_transfers.cpp73
1 files changed, 57 insertions, 16 deletions
diff --git a/plugins/Dropbox/src/dropbox_transfers.cpp b/plugins/Dropbox/src/dropbox_transfers.cpp
index 54c2f854af..519e191479 100644
--- a/plugins/Dropbox/src/dropbox_transfers.cpp
+++ b/plugins/Dropbox/src/dropbox_transfers.cpp
@@ -76,15 +76,6 @@ void CDropbox::SendFileChunkedNext(const char *data, int length, const char *upl
void CDropbox::SendFileChunkedLast(const char *fileName, const char *uploadId, MCONTACT hContact)
{
- /*char url[MAX_PATH];
- mir_snprintf(
- url,
- SIZEOF(url),
- "%s/commit_chunked_upload/%s/%s",
- DROPBOX_APICONTENT_URL,
- DROPBOX_API_ROOT,
- fileName);*/
-
CMStringA url;
url.AppendFormat(
"%s/commit_chunked_upload/%s/%s",
@@ -92,7 +83,6 @@ void CDropbox::SendFileChunkedLast(const char *fileName, const char *uploadId, M
DROPBOX_API_ROOT,
fileName);
url.Replace('\\', '/');
-
HttpRequest *request = new HttpRequest(hNetlibUser, REQUEST_POST, url);
request->AddParameter("upload_id", uploadId);
@@ -104,7 +94,7 @@ void CDropbox::SendFileChunkedLast(const char *fileName, const char *uploadId, M
if (response)
{
- if (response->resultCode == HttpStatus::OK)
+ if (response->resultCode == HttpStatus::OK && !strchr(fileName, '\\'))
{
url.Replace(DROPBOX_APICONTENT_URL, DROPBOX_API_URL);
url.Replace("commit_chunked_upload", "shares");
@@ -154,8 +144,11 @@ void CDropbox::SendFileChunkedLast(const char *fileName, const char *uploadId, M
}
}
-void CDropbox::CreateFolder(const char *folderName)
+void CDropbox::CreateFolder(const char *folderName, MCONTACT hContact)
{
+ CMStringA folder = folderName;
+ folder.Replace('\\', '/');
+
HttpRequest *request = new HttpRequest(hNetlibUser, REQUEST_POST, DROPBOX_API_URL "/fileops/create_folder");
request->AddParameter("root", DROPBOX_API_ROOT);
request->AddParameter("path", folderName);
@@ -167,11 +160,59 @@ void CDropbox::CreateFolder(const char *folderName)
if (response)
{
- /*if (response->resultCode == HttpStatus::OK)
+ if (response->resultCode == HttpStatus::OK && !strchr(folderName, '\\'))
{
- }*/
+ char url[MAX_PATH];
+ mir_snprintf(
+ url,
+ SIZEOF(url),
+ "%s/shares/%s/%s",
+ DROPBOX_API_URL,
+ DROPBOX_API_ROOT,
+ folder.GetBuffer());
- mir_free(response);
+ request = new HttpRequest(hNetlibUser, REQUEST_POST, url);
+ request->AddParameter("access_token", db_get_sa(NULL, MODULE, "TokenSecret"));
+
+ mir_free(response);
+
+ response = request->Send();
+
+ if (response)
+ {
+ if (response->resultCode == HttpStatus::OK)
+ {
+ JSONNODE *root = json_parse(response->pData);
+ if (root != NULL)
+ {
+ JSONNODE *node = json_get(root, "url");
+ char message[1024];
+ mir_snprintf(
+ message,
+ SIZEOF(message),
+ Translate("Link to download folder \"%s\": %s"),
+ folderName,
+ mir_utf8encodeW(json_as_string(node)));
+
+ DBEVENTINFO dbei = { sizeof(dbei) };
+ dbei.szModule = MODULE;
+ dbei.timestamp = time(NULL);
+ dbei.eventType = EVENTTYPE_MESSAGE;
+ dbei.cbBlob = strlen(message);
+ dbei.pBlob = (PBYTE)mir_strdup(message);
+ dbei.flags = DBEF_UTF;
+ ::db_event_add(hContact, &dbei);
+
+ delete node;
+ delete root;
+ }
+ }
+
+ mir_free(response);
+ }
+ }
+ else
+ mir_free(response);
}
}
@@ -182,7 +223,7 @@ void _cdecl CDropbox::SendFileAsync(void *arg)
ProtoBroadcastAck(MODULE, ftp->pfts.hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, ftp->hProcess, 0);
for (int i = 0; ftp->pszFolders[i]; i++)
- Singleton<CDropbox>::GetInstance()->CreateFolder(ftp->pszFolders[i]);
+ Singleton<CDropbox>::GetInstance()->CreateFolder(ftp->pszFolders[i], ftp->pfts.hContact);
for (int i = 0; ftp->pfts.pszFiles[i]; i++)
{