diff options
author | aunsane <aunsane@gmail.com> | 2017-04-09 17:38:37 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2017-04-09 17:39:06 +0300 |
commit | 6481053a2d97d73902b4ba86b7a06812cff48ae1 (patch) | |
tree | 903ba40ce35761b32084951aede67c6eee9dd2c1 /plugins/Dropbox/src/dropbox_transfers.cpp | |
parent | 3f6bdf928ebf7e7e70d999905eb363386db2868a (diff) |
Dropbox: temporary url option
Diffstat (limited to 'plugins/Dropbox/src/dropbox_transfers.cpp')
-rw-r--r-- | plugins/Dropbox/src/dropbox_transfers.cpp | 70 |
1 files changed, 42 insertions, 28 deletions
diff --git a/plugins/Dropbox/src/dropbox_transfers.cpp b/plugins/Dropbox/src/dropbox_transfers.cpp index 556bccbcfc..7f7bf2b1e7 100644 --- a/plugins/Dropbox/src/dropbox_transfers.cpp +++ b/plugins/Dropbox/src/dropbox_transfers.cpp @@ -7,14 +7,10 @@ char* CDropbox::UploadFile(const char *data, size_t size, char *path) UploadFileRequest request(token, encodedPath, data, size);
NLHR_PTR response(request.Send(hNetlibConnection));
- HandleJsonResponseError(response);
+ JSONNode root = HandleJsonResponse(response);
+ JSONNode node = root.at("path_lower");
+ mir_strcpy(path, node.as_string().c_str());
- JSONNode root = JSONNode::parse(response->pData);
- if (!root.empty())
- {
- JSONNode node = root.at("path_lower");
- mir_strcpy(path, node.as_string().c_str());
- }
return path;
}
@@ -24,12 +20,7 @@ void CDropbox::StartUploadSession(const char *data, size_t size, char *sessionId StartUploadSessionRequest request(token, data, size);
NLHR_PTR response(request.Send(hNetlibConnection));
- HandleJsonResponseError(response);
-
- JSONNode root = JSONNode::parse(response->pData);
- if (root.empty())
- return;
-
+ JSONNode root = HandleJsonResponse(response);
JSONNode node = root.at("session_id");
mir_strcpy(sessionId, node.as_string().c_str());
}
@@ -40,7 +31,7 @@ void CDropbox::AppendToUploadSession(const char *data, size_t size, const char * AppendToUploadSessionRequest request(token, sessionId, offset, data, size);
NLHR_PTR response(request.Send(hNetlibConnection));
- HandleJsonResponseError(response);
+ HandleJsonResponse(response);
}
char* CDropbox::FinishUploadSession(const char *data, size_t size, const char *sessionId, size_t offset, char *path)
@@ -49,14 +40,10 @@ char* CDropbox::FinishUploadSession(const char *data, size_t size, const char *s FinishUploadSessionRequest request(token, sessionId, offset, path, data, size);
NLHR_PTR response(request.Send(hNetlibConnection));
- HandleJsonResponseError(response);
+ JSONNode root = HandleJsonResponse(response);
+ JSONNode node = root.at("path_lower");
+ mir_strcpy(path, node.as_string().c_str());
- JSONNode root = JSONNode::parse(response->pData);
- if (!root.empty())
- {
- JSONNode node = root.at("path_lower");
- mir_strcpy(path, node.as_string().c_str());
- }
return path;
}
@@ -70,23 +57,50 @@ void CDropbox::CreateFolder(const char *path) if (response->resultCode == HTTP_STATUS_FORBIDDEN)
return;
- HandleJsonResponseError(response);
+ HandleJsonResponse(response);
}
void CDropbox::CreateDownloadUrl(const char *path, char *url)
{
ptrA token(db_get_sa(NULL, MODULE, "TokenSecret"));
- GetTemporaryLinkRequest request(token, path);
- NLHR_PTR response(request.Send(hNetlibConnection));
+ if (db_get_b(NULL, MODULE, "UrlIsTemporary", 0)) {
+ GetTemporaryLinkRequest request(token, path);
+ NLHR_PTR response(request.Send(hNetlibConnection));
- HandleJsonResponseError(response);
+ JSONNode root = HandleJsonResponse(response);
+ JSONNode link = root.at("link");
+ mir_strcpy(url, link.as_string().c_str());
+ return;
+ }
+
+ CreateSharedLinkRequest shareRequest(token, path);
+ NLHR_PTR response(shareRequest.Send(hNetlibConnection));
+
+ HandleHttpResponse(response);
JSONNode root = JSONNode::parse(response->pData);
- if (root.empty())
+ if (root.isnull())
+ throw DropboxException(HttpStatusToText(HTTP_STATUS_ERROR));
+
+ JSONNode error = root.at("error");
+ if (error.isnull()) {
+ JSONNode link = root.at("link");
+ mir_strcpy(url, link.as_string().c_str());
return;
+ }
+
+ json_string tag = error.at(".tag").as_string();
+ if (tag != "shared_link_already_exists")
+ throw DropboxException(tag.c_str());
+
+ GetSharedLinkRequest getRequest(token, path);
+ response = getRequest.Send(hNetlibConnection);
+
+ root = HandleJsonResponse(response);
- JSONNode node = root.at("link");
- mir_strcpy(url, node.as_string().c_str());
+ JSONNode links = root.at("links").as_array();
+ JSONNode link = links[0u].at("url");
+ mir_strcpy(url, link.as_string().c_str());
}
UINT CDropbox::UploadToDropbox(void *owner, void *arg)
|