From ae52dee4a7b2e108dc260d52ce0e0bde78474ac9 Mon Sep 17 00:00:00 2001 From: aunsane Date: Tue, 9 May 2017 23:04:10 +0300 Subject: CloudFile: fix upload --- plugins/CloudFile/src/Services/dropbox_service.cpp | 9 +++------ plugins/CloudFile/src/Services/dropbox_service.h | 4 ++-- plugins/CloudFile/src/Services/google_api.h | 2 +- plugins/CloudFile/src/Services/google_service.cpp | 3 +-- plugins/CloudFile/src/Services/microsoft_service.cpp | 5 +++-- plugins/CloudFile/src/Services/yandex_service.cpp | 3 +-- 6 files changed, 11 insertions(+), 15 deletions(-) (limited to 'plugins/CloudFile/src/Services') diff --git a/plugins/CloudFile/src/Services/dropbox_service.cpp b/plugins/CloudFile/src/Services/dropbox_service.cpp index ef70949d55..520cdf1378 100644 --- a/plugins/CloudFile/src/Services/dropbox_service.cpp +++ b/plugins/CloudFile/src/Services/dropbox_service.cpp @@ -136,10 +136,10 @@ void CDropboxService::UploadFileChunk(const char *chunk, size_t chunkSize, const DropboxAPI::UploadFileChunkRequest request(token, sessionId, offset, chunk, chunkSize); NLHR_PTR response(request.Send(hConnection)); - GetJsonResponse(response); + HandleHttpError(response); } -char* CDropboxService::CommitUploadSession(const char *data, size_t size, const char *sessionId, size_t offset, char *path) +void CDropboxService::CommitUploadSession(const char *data, size_t size, const char *sessionId, size_t offset, char *path) { ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret")); DropboxAPI::CommitUploadSessionRequest request(token, sessionId, offset, path, data, size); @@ -148,8 +148,6 @@ char* CDropboxService::CommitUploadSession(const char *data, size_t size, const JSONNode root = GetJsonResponse(response); JSONNode node = root.at("path_lower"); mir_strcpy(path, node.as_string().c_str()); - - return path; } void CDropboxService::CreateFolder(const char *path) @@ -243,8 +241,7 @@ UINT CDropboxService::Upload(FileTransferParam *ftp) size_t offset = size; double chunkCount = ceil(double(fileSize) / chunkSize) - 2; - while (chunkCount--) - { + while (chunkCount > 0) { ftp->CheckCurrentFile(); size = ftp->ReadCurrentFile(data, chunkSize); diff --git a/plugins/CloudFile/src/Services/dropbox_service.h b/plugins/CloudFile/src/Services/dropbox_service.h index c498b52178..90dc11d259 100644 --- a/plugins/CloudFile/src/Services/dropbox_service.h +++ b/plugins/CloudFile/src/Services/dropbox_service.h @@ -9,10 +9,10 @@ private: void HandleJsonError(JSONNode &node); - char* UploadFile(const char *data, size_t size, char *path); + void UploadFile(const char *data, size_t size, char *path); void CreateUploadSession(const char *chunk, size_t chunkSize, char *sessionId); void UploadFileChunk(const char *chunk, size_t chunkSize, const char *sessionId, size_t offset); - char* CommitUploadSession(const char *chunk, size_t chunkSize, const char *sessionId, size_t offset, char *path); + void CommitUploadSession(const char *chunk, size_t chunkSize, const char *sessionId, size_t offset, char *path); void CreateFolder(const char *path); void CreateSharedLink(const char *path, char *url); diff --git a/plugins/CloudFile/src/Services/google_api.h b/plugins/CloudFile/src/Services/google_api.h index c73124cdad..476a97a0e2 100644 --- a/plugins/CloudFile/src/Services/google_api.h +++ b/plugins/CloudFile/src/Services/google_api.h @@ -67,7 +67,7 @@ namespace GDriveAPI body.AppendChar(0x0A); body.Append("{"); body.AppendFormat("\"name\": \"%s\"", name); - if (parentId) + if (mir_strlen(parentId)) body.AppendFormat("\"parents\": [\"%s\"]", parentId); body.Append("}"); body.AppendChar(0x0A); diff --git a/plugins/CloudFile/src/Services/google_service.cpp b/plugins/CloudFile/src/Services/google_service.cpp index 92e704bbac..3fc7111822 100644 --- a/plugins/CloudFile/src/Services/google_service.cpp +++ b/plugins/CloudFile/src/Services/google_service.cpp @@ -264,8 +264,7 @@ UINT CGDriveService::Upload(FileTransferParam *ftp) uint64_t offset = 0; double chunkCount = ceil(double(fileSize) / chunkSize); - while (chunkCount--) - { + while (chunkCount > 0) { ftp->CheckCurrentFile(); size_t size = ftp->ReadCurrentFile(chunk, chunkSize); diff --git a/plugins/CloudFile/src/Services/microsoft_service.cpp b/plugins/CloudFile/src/Services/microsoft_service.cpp index 77919574e0..af4dd6f703 100644 --- a/plugins/CloudFile/src/Services/microsoft_service.cpp +++ b/plugins/CloudFile/src/Services/microsoft_service.cpp @@ -35,7 +35,7 @@ void COneDriveService::Login() { ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret")); ptrA refreshToken(db_get_sa(NULL, GetModule(), "RefreshToken")); - if (token && refreshToken && refreshToken[0]) { + if (token && refreshToken && refreshToken[0]) { OneDriveAPI::RefreshTokenRequest request(refreshToken); NLHR_PTR response(request.Send(hConnection)); @@ -246,7 +246,8 @@ UINT COneDriveService::Upload(FileTransferParam *ftp) CreateUploadSession(uploadUri, T2Utf(fileName), folderId); uint64_t offset = 0; - for (size_t i = 0; i < (fileSize / chunkSize); i++) { + double chunkCount = ceil(double(fileSize) / chunkSize); + while (chunkCount > 0) { ftp->CheckCurrentFile(); size_t size = ftp->ReadCurrentFile(chunk, chunkSize); diff --git a/plugins/CloudFile/src/Services/yandex_service.cpp b/plugins/CloudFile/src/Services/yandex_service.cpp index 167d9cc3f8..04d63138c0 100644 --- a/plugins/CloudFile/src/Services/yandex_service.cpp +++ b/plugins/CloudFile/src/Services/yandex_service.cpp @@ -250,8 +250,7 @@ UINT CYandexService::Upload(FileTransferParam *ftp) else { uint64_t offset = 0; double chunkCount = ceil(double(fileSize) / chunkSize); - while (chunkCount--) - { + while (chunkCount > 0) { ftp->CheckCurrentFile(); size_t size = ftp->ReadCurrentFile(chunk, chunkSize); -- cgit v1.2.3