diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2014-02-20 17:33:44 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2014-02-20 17:33:44 +0000 |
commit | b9567416b251f589ba5ac4ed1dadc644e79d6912 (patch) | |
tree | 4e1a9e2a3a926be13cc463a19a4a685c0bfdb24f /plugins/Dropbox/src | |
parent | 4c6a62618e1e03f97d0f194a37316a97c6ea5062 (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')
-rw-r--r-- | plugins/Dropbox/src/dropbox.h | 10 | ||||
-rw-r--r-- | plugins/Dropbox/src/dropbox_transfers.cpp | 73 |
2 files changed, 62 insertions, 21 deletions
diff --git a/plugins/Dropbox/src/dropbox.h b/plugins/Dropbox/src/dropbox.h index 0789f508c7..c2aed06ec8 100644 --- a/plugins/Dropbox/src/dropbox.h +++ b/plugins/Dropbox/src/dropbox.h @@ -51,11 +51,11 @@ struct FileTransferParam ~FileTransferParam()
{
- /*if (pfts.pszFiles)
+ if (pfts.pszFiles)
{
for (int i = 0; pfts.pszFiles[i]; i++)
{
- if (pfts.pszFiles[i]) delete pfts.pszFiles[i];
+ if (pfts.pszFiles[i]) mir_free(pfts.pszFiles[i]);
}
delete pfts.pszFiles;
}
@@ -64,10 +64,10 @@ struct FileTransferParam {
for (int i = 0; pszFolders[i]; i++)
{
- if (pszFolders[i]) delete pszFolders[i];
+ if (pszFolders[i]) mir_free(pszFolders[i]);
}
delete pszFolders;
- }*/
+ }
}
};
@@ -108,7 +108,7 @@ private: void SendFileChunkedNext(const char *data, int length, const char *uploadId, int &offset);
void SendFileChunkedLast(const char *fileName, const char *uploadId, MCONTACT hContact);
- void CreateFolder(const char *folderName);
+ void CreateFolder(const char *folderName, MCONTACT hContact);
static void _cdecl SendFileAsync(void *arg);
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++)
{
|