summaryrefslogtreecommitdiff
path: root/plugins/CloudFile
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2017-04-26 00:01:56 +0300
committeraunsane <aunsane@gmail.com>2017-04-26 00:02:28 +0300
commitc336d52ffabca5777b5c6666cff818ac742480bf (patch)
treed30c0a67c6dfa3ac06cd401c6973145f7e18509b /plugins/CloudFile
parentf6575a156251f15ca2c1b9d8042aa45fb62bf42a (diff)
CloudFile: OneDrive is worked now
Diffstat (limited to 'plugins/CloudFile')
-rw-r--r--plugins/CloudFile/src/Services/microsoft_api.h30
-rw-r--r--plugins/CloudFile/src/Services/microsoft_service.cpp31
-rw-r--r--plugins/CloudFile/src/Services/microsoft_service.h1
-rw-r--r--plugins/CloudFile/src/cloud_service.cpp5
4 files changed, 35 insertions, 32 deletions
diff --git a/plugins/CloudFile/src/Services/microsoft_api.h b/plugins/CloudFile/src/Services/microsoft_api.h
index 0717a7a00a..1c3c323520 100644
--- a/plugins/CloudFile/src/Services/microsoft_api.h
+++ b/plugins/CloudFile/src/Services/microsoft_api.h
@@ -51,16 +51,20 @@ namespace OneDriveAPI
{
public:
CreateUploadSessionRequest(const char *token, const char *name) :
- HttpRequest(REQUEST_POST, FORMAT, ONEDRIVE_API "/root:/%s:/createUploadSession", name)
+ HttpRequest(REQUEST_POST, FORMAT, ONEDRIVE_API "/special/approot:/%s:/createUploadSession", name)
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/json");
- JSONNode params(JSON_NODE);
- params
+ JSONNode item(JSON_NODE);
+ item.set_name("item");
+ item
<< JSONNode("@microsoft.graph.conflictBehavior", "rename")
<< JSONNode("name", name);
+ JSONNode params(JSON_NODE);
+ params << item;
+
json_string data = params.write();
SetData(data.c_str(), data.length());
}
@@ -71,11 +75,15 @@ namespace OneDriveAPI
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/json");
- JSONNode params(JSON_NODE);
- params
+ JSONNode item(JSON_NODE);
+ item.set_name("item");
+ item
<< JSONNode("@microsoft.graph.conflictBehavior", "rename")
<< JSONNode("name", name);
+ JSONNode params(JSON_NODE);
+ params << item;
+
json_string data = params.write();
SetData(data.c_str(), data.length());
}
@@ -100,15 +108,19 @@ namespace OneDriveAPI
{
public:
CreateFolderRequest(const char *token, const char *path) :
- HttpRequest(REQUEST_PUT, ONEDRIVE_API "/items/root/children")
+ HttpRequest(REQUEST_PUT, ONEDRIVE_API "/special/approot/children")
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/json");
+ JSONNode folder(JSON_NODE);
+ folder.set_name("folder");
+ folder << JSONNode(JSON_NODE);
+
JSONNode params(JSON_NODE);
params
<< JSONNode("name", path)
- << JSONNode("folder", "");
+ << folder;
json_string data = params.write();
SetData(data.c_str(), data.length());
@@ -118,8 +130,8 @@ namespace OneDriveAPI
class CreateSharedLinkRequest : public HttpRequest
{
public:
- CreateSharedLinkRequest(const char *token, const char *path) :
- HttpRequest(REQUEST_POST, FORMAT, ONEDRIVE_API "/items/%s/createLink", path)
+ CreateSharedLinkRequest(const char *token, const char *itemId) :
+ HttpRequest(REQUEST_POST, FORMAT, ONEDRIVE_API "/items/%s/createLink", itemId)
{
AddBearerAuthHeader(token);
AddHeader("Content-Type", "application/json");
diff --git a/plugins/CloudFile/src/Services/microsoft_service.cpp b/plugins/CloudFile/src/Services/microsoft_service.cpp
index d988ec222a..b8351019ed 100644
--- a/plugins/CloudFile/src/Services/microsoft_service.cpp
+++ b/plugins/CloudFile/src/Services/microsoft_service.cpp
@@ -57,7 +57,9 @@ void COneDriveService::Login()
void COneDriveService::Logout()
{
- mir_forkthreadex(RevokeAccessTokenThread, this);
+ db_unset(NULL, GetModule(), "TokenSecret");
+ db_unset(NULL, GetModule(), "ExpiresIn");
+ db_unset(NULL, GetModule(), "RefreshToken");
}
unsigned COneDriveService::RequestAccessTokenThread(void *owner, void *param)
@@ -91,7 +93,7 @@ unsigned COneDriveService::RequestAccessTokenThread(void *owner, void *param)
return 0;
}
- JSONNode node = root.at("error");
+ JSONNode node = root.at("error_description");
if (!node.isnull()) {
ptrW error_description(mir_a2u_cp(node.as_string().c_str(), CP_UTF8));
Netlib_Logf(service->hConnection, "%s: %s", service->GetModule(), service->HttpStatusToError(response->resultCode));
@@ -116,17 +118,6 @@ unsigned COneDriveService::RequestAccessTokenThread(void *owner, void *param)
return 0;
}
-unsigned COneDriveService::RevokeAccessTokenThread(void *param)
-{
- //COneDriveService *service = (COneDriveService*)param;
-
- /*ptrA token(db_get_sa(NULL, service->GetModule(), "TokenSecret"));
- OneDriveAPI::RevokeAccessTokenRequest request(token);
- NLHR_PTR response(request.Send(service->hConnection));*/
-
- return 0;
-}
-
void COneDriveService::HandleJsonError(JSONNode &node)
{
JSONNode error = node.at("error");
@@ -139,10 +130,11 @@ void COneDriveService::HandleJsonError(JSONNode &node)
void COneDriveService::CreateUploadSession(char *uploadUri, const char *name, const char *parentId)
{
ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
- OneDriveAPI::CreateUploadSessionRequest request = mir_strlen(parentId)
- ? OneDriveAPI::CreateUploadSessionRequest(token, parentId, name)
- : OneDriveAPI::CreateUploadSessionRequest(token, name);
- NLHR_PTR response(request.Send(hConnection));
+ OneDriveAPI::CreateUploadSessionRequest *request = mir_strlen(parentId)
+ ? new OneDriveAPI::CreateUploadSessionRequest(token, parentId, name)
+ : new OneDriveAPI::CreateUploadSessionRequest(token, name);
+ NLHR_PTR response(request->Send(hConnection));
+ delete request;
JSONNode root = GetJsonResponse(response);
JSONNode node = root.at("uploadUrl");
@@ -190,8 +182,9 @@ void COneDriveService::CreateSharedLink(const char *itemId, char *url)
NLHR_PTR response(request.Send(hConnection));
JSONNode root = GetJsonResponse(response);
- JSONNode node = root.at("webUrl");
- mir_strcpy(url, node.as_string().c_str());
+ JSONNode node = root.at("link");
+ JSONNode webUrl = root.at("webUrl");
+ mir_strcpy(url, webUrl.as_string().c_str());
}
UINT COneDriveService::Upload(FileTransferParam *ftp)
diff --git a/plugins/CloudFile/src/Services/microsoft_service.h b/plugins/CloudFile/src/Services/microsoft_service.h
index 7853378e07..8c3c30e035 100644
--- a/plugins/CloudFile/src/Services/microsoft_service.h
+++ b/plugins/CloudFile/src/Services/microsoft_service.h
@@ -5,7 +5,6 @@ class COneDriveService : public CCloudService
{
private:
static unsigned RequestAccessTokenThread(void *owner, void *param);
- static unsigned __stdcall RevokeAccessTokenThread(void *param);
void HandleJsonError(JSONNode &node);
diff --git a/plugins/CloudFile/src/cloud_service.cpp b/plugins/CloudFile/src/cloud_service.cpp
index 3f35bc1d4b..bbee441372 100644
--- a/plugins/CloudFile/src/cloud_service.cpp
+++ b/plugins/CloudFile/src/cloud_service.cpp
@@ -11,7 +11,7 @@ void InitServices()
{
Services.insert(new CDropboxService(hNetlibConnection));
Services.insert(new CGDriveService(hNetlibConnection));
- //Services.insert(new COneDriveService(hNetlibConnection));
+ Services.insert(new COneDriveService(hNetlibConnection));
Services.insert(new CYandexService(hNetlibConnection));
PROTOCOLDESCRIPTOR pd = { sizeof(pd) };
@@ -146,8 +146,7 @@ void CCloudService::HandleHttpError(NETLIBHTTPREQUEST *response)
if (response == NULL)
throw Exception(HttpStatusToError());
- if (response->resultCode != HTTP_CODE_OK &&
- response->resultCode != HTTP_CODE_CONFLICT) {
+ if (!HTTP_CODE_SUCCESS(response->resultCode)) {
if (response->dataLength)
throw Exception(response->pData);
throw Exception(HttpStatusToError(response->resultCode));