summaryrefslogtreecommitdiff
path: root/plugins/CloudFile
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2017-05-10 00:38:42 +0300
committeraunsane <aunsane@gmail.com>2017-05-10 00:38:42 +0300
commit6cb4fe7726c5672a5b6776d83976ed851d8332c2 (patch)
treeb7464f6d6105d70708d08ddb6d9b5524c3b22832 /plugins/CloudFile
parente6b569f5f636c548fa253171f86b7a0f96fe1817 (diff)
CloudFile: fix "on conflict" fox dropbox
Diffstat (limited to 'plugins/CloudFile')
-rw-r--r--plugins/CloudFile/src/Services/dropbox_api.h30
-rw-r--r--plugins/CloudFile/src/Services/dropbox_service.cpp60
-rw-r--r--plugins/CloudFile/src/Services/google_service.cpp2
-rw-r--r--plugins/CloudFile/src/Services/microsoft_service.cpp6
-rw-r--r--plugins/CloudFile/src/Services/yandex_service.cpp7
-rw-r--r--plugins/CloudFile/src/options.cpp2
6 files changed, 75 insertions, 32 deletions
diff --git a/plugins/CloudFile/src/Services/dropbox_api.h b/plugins/CloudFile/src/Services/dropbox_api.h
index 890ff420f6..fefb6ef70d 100644
--- a/plugins/CloudFile/src/Services/dropbox_api.h
+++ b/plugins/CloudFile/src/Services/dropbox_api.h
@@ -41,7 +41,7 @@ namespace DropboxAPI
class UploadFileRequest : public HttpRequest
{
public:
- UploadFileRequest(const char *token, const char *path, const char *data, size_t size) :
+ UploadFileRequest(const char *token, const char *path, const char *data, size_t size, OnConflict strategy = NONE) :
HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload")
{
AddBearerAuthHeader(token);
@@ -49,8 +49,17 @@ namespace DropboxAPI
JSONNode params(JSON_NODE);
params
- << JSONNode("path", path)
- << JSONNode("mode", "overwrite");
+ << JSONNode("path", path);
+ if (strategy == OnConflict::RENAME) {
+ params
+ << JSONNode("mode", "add")
+ << JSONNode("autorename", true);
+ }
+ else if (strategy == OnConflict::REPLACE) {
+ params
+ << JSONNode("mode", "overwrite")
+ << JSONNode("autorename", false);
+ }
AddHeader("Dropbox-API-Arg", params.write().c_str());
@@ -99,7 +108,7 @@ namespace DropboxAPI
class CommitUploadSessionRequest : public HttpRequest
{
public:
- CommitUploadSessionRequest(const char *token, const char *sessionId, size_t offset, const char *path, const char *chunk, size_t chunkSize) :
+ CommitUploadSessionRequest(const char *token, const char *sessionId, size_t offset, const char *path, const char *chunk, size_t chunkSize, OnConflict strategy = NONE) :
HttpRequest(REQUEST_POST, DROPBOX_API_CU "/files/upload_session/finish")
{
AddBearerAuthHeader(token);
@@ -114,8 +123,17 @@ namespace DropboxAPI
JSONNode commit(JSON_NODE);
commit.set_name("commit");
commit
- << JSONNode("path", path)
- << JSONNode("mode", "overwrite");
+ << JSONNode("path", path);
+ if (strategy == OnConflict::RENAME) {
+ commit
+ << JSONNode("mode", "add")
+ << JSONNode("autorename", true);
+ }
+ else if (strategy == OnConflict::REPLACE) {
+ commit
+ << JSONNode("mode", "overwrite")
+ << JSONNode("autorename", false);
+ }
JSONNode params(JSON_NODE);
params
diff --git a/plugins/CloudFile/src/Services/dropbox_service.cpp b/plugins/CloudFile/src/Services/dropbox_service.cpp
index 04d4694143..2bdb577c19 100644
--- a/plugins/CloudFile/src/Services/dropbox_service.cpp
+++ b/plugins/CloudFile/src/Services/dropbox_service.cpp
@@ -108,8 +108,9 @@ void CDropboxService::HandleJsonError(JSONNode &node)
void CDropboxService::UploadFile(const char *data, size_t size, char *path)
{
ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
+ BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
ptrA encodedPath(mir_utf8encode(path));
- DropboxAPI::UploadFileRequest request(token, encodedPath, data, size);
+ DropboxAPI::UploadFileRequest request(token, encodedPath, data, size, (OnConflict)strategy);
NLHR_PTR response(request.Send(hConnection));
JSONNode root = GetJsonResponse(response);
@@ -140,7 +141,8 @@ void CDropboxService::UploadFileChunk(const char *chunk, size_t chunkSize, const
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);
+ BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
+ DropboxAPI::CommitUploadSessionRequest request(token, sessionId, offset, path, data, size, (OnConflict)strategy);
NLHR_PTR response(request.Send(hConnection));
JSONNode root = GetJsonResponse(response);
@@ -229,35 +231,51 @@ UINT CDropboxService::Upload(FileTransferParam *ftp)
uint64_t fileSize = ftp->GetCurrentFileSize();
int chunkSize = ftp->GetCurrentFileChunkSize();
- mir_ptr<char>data((char*)mir_calloc(chunkSize));
+ mir_ptr<char>chunk((char*)mir_calloc(chunkSize));
- char sessionId[64];
- size_t size = ftp->ReadCurrentFile(data, chunkSize);
- CreateUploadSession(data, size, sessionId);
-
- ftp->Progress(size);
+ char path[MAX_PATH];
+ PreparePath(fileName, path);
- size_t offset = size;
- double chunkCount = ceil(double(fileSize) / chunkSize) - 2;
- while (chunkCount > 0) {
+ if (chunkSize == fileSize)
+ {
ftp->CheckCurrentFile();
+ size_t size = ftp->ReadCurrentFile(chunk, chunkSize);
- size = ftp->ReadCurrentFile(data, chunkSize);
- UploadFileChunk(data, size, sessionId, offset);
+ UploadFile(chunk, size, path);
- offset += size;
ftp->Progress(size);
}
+ else
+ {
+ ftp->CheckCurrentFile();
+ size_t size = ftp->ReadCurrentFile(chunk, chunkSize);
- size = offset < fileSize
- ? ftp->ReadCurrentFile(data, fileSize - offset)
- : 0;
+ char sessionId[64];
+ CreateUploadSession(chunk, size, sessionId);
- char path[MAX_PATH];
- PreparePath(fileName, path);
- CommitUploadSession(data, size, sessionId, offset, path);
+ ftp->Progress(size);
+
+ size_t offset = size;
+ double chunkCount = ceil(double(fileSize) / chunkSize) - 2;
+ while (chunkCount > 0) {
+ ftp->CheckCurrentFile();
- ftp->Progress(size);
+ size = ftp->ReadCurrentFile(chunk, chunkSize);
+ UploadFileChunk(chunk, size, sessionId, offset);
+
+ offset += size;
+ ftp->Progress(size);
+ }
+
+ ftp->CheckCurrentFile();
+ size = offset < fileSize
+ ? ftp->ReadCurrentFile(chunk, fileSize - offset)
+ : 0;
+
+ CommitUploadSession(chunk, size, sessionId, offset, path);
+
+ ftp->Progress(size);
+ }
if (!ftp->IsFolder()) {
char url[MAX_PATH];
diff --git a/plugins/CloudFile/src/Services/google_service.cpp b/plugins/CloudFile/src/Services/google_service.cpp
index 3fc7111822..0f5e2c793d 100644
--- a/plugins/CloudFile/src/Services/google_service.cpp
+++ b/plugins/CloudFile/src/Services/google_service.cpp
@@ -256,6 +256,8 @@ UINT CGDriveService::Upload(FileTransferParam *ftp)
size_t size = ftp->ReadCurrentFile(chunk, chunkSize);
UploadFile(folderId, fileName, chunk, size, fileId);
+
+ ftp->Progress(size);
}
else
{
diff --git a/plugins/CloudFile/src/Services/microsoft_service.cpp b/plugins/CloudFile/src/Services/microsoft_service.cpp
index aa2b8613b4..194d117df8 100644
--- a/plugins/CloudFile/src/Services/microsoft_service.cpp
+++ b/plugins/CloudFile/src/Services/microsoft_service.cpp
@@ -130,7 +130,7 @@ void COneDriveService::HandleJsonError(JSONNode &node)
void COneDriveService::UploadFile(const char *parentId, const char *name, const char *data, size_t size, char *fileId)
{
ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
- BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::NONE);
+ BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
OneDriveAPI::UploadFileRequest *request = mir_strlen(parentId)
? new OneDriveAPI::UploadFileRequest(token, parentId, name, data, size, (OnConflict)strategy)
: new OneDriveAPI::UploadFileRequest(token, name, data, size, (OnConflict)strategy);
@@ -145,7 +145,7 @@ void COneDriveService::UploadFile(const char *parentId, const char *name, const
void COneDriveService::CreateUploadSession(const char *parentId, const char *name, char *uploadUri)
{
ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
- BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::NONE);
+ BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
OneDriveAPI::CreateUploadSessionRequest *request = mir_strlen(parentId)
? new OneDriveAPI::CreateUploadSessionRequest(token, parentId, name, (OnConflict)strategy)
: new OneDriveAPI::CreateUploadSessionRequest(token, name, (OnConflict)strategy);
@@ -241,6 +241,8 @@ UINT COneDriveService::Upload(FileTransferParam *ftp)
size_t size = ftp->ReadCurrentFile(chunk, chunkSize);
UploadFile(folderId, T2Utf(fileName), chunk, size, fileId);
+
+ ftp->Progress(size);
}
else
{
diff --git a/plugins/CloudFile/src/Services/yandex_service.cpp b/plugins/CloudFile/src/Services/yandex_service.cpp
index cef1aadc45..d012dd3cc8 100644
--- a/plugins/CloudFile/src/Services/yandex_service.cpp
+++ b/plugins/CloudFile/src/Services/yandex_service.cpp
@@ -142,7 +142,7 @@ void CYandexService::HandleJsonError(JSONNode &node)
void CYandexService::CreateUploadSession(const char *path, char *uploadUri)
{
ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret"));
- BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::NONE);
+ BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
YandexAPI::GetUploadUrlRequest request(token, path, (OnConflict)strategy);
NLHR_PTR response(request.Send(hConnection));
@@ -247,8 +247,11 @@ UINT CYandexService::Upload(FileTransferParam *ftp)
size_t size = ftp->ReadCurrentFile(chunk, chunkSize);
UploadFile(uploadUri, chunk, size);
+
+ ftp->Progress(size);
}
- else {
+ else
+ {
uint64_t offset = 0;
double chunkCount = ceil(double(fileSize) / chunkSize);
while (chunkCount > 0) {
diff --git a/plugins/CloudFile/src/options.cpp b/plugins/CloudFile/src/options.cpp
index 11abf03c01..b2b1db8d5e 100644
--- a/plugins/CloudFile/src/options.cpp
+++ b/plugins/CloudFile/src/options.cpp
@@ -37,7 +37,7 @@ void COptionsMain::OnInitDialog()
m_defaultService.SetCurSel(iItem);
}
- BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::NONE);
+ BYTE strategy = db_get_b(NULL, MODULE, "ConflictStrategy", OnConflict::REPLACE);
if (strategy == OnConflict::RENAME)
m_renameOnConflict.SetState(TRUE);
else if (strategy == OnConflict::REPLACE)