diff options
author | aunsane <aunsane@gmail.com> | 2018-04-21 20:45:34 +0300 |
---|---|---|
committer | aunsane <aunsane@gmail.com> | 2018-04-21 20:45:53 +0300 |
commit | a74debb40c3df12738c722548c556a97e5976036 (patch) | |
tree | f3c2e224d75b64de547778625122d6242e558f36 /plugins/CloudFile/src/Services/yandex_service.cpp | |
parent | 803e7b0b5e7c84a814601141fcb7634516eefa30 (diff) |
CloudFile:
- fix #1278
- decrease volume of response data with fields filtering
- fix uploading for gdrive and onedrive in some cases
- simplifying upload code
- version bump
Diffstat (limited to 'plugins/CloudFile/src/Services/yandex_service.cpp')
-rw-r--r-- | plugins/CloudFile/src/Services/yandex_service.cpp | 94 |
1 files changed, 40 insertions, 54 deletions
diff --git a/plugins/CloudFile/src/Services/yandex_service.cpp b/plugins/CloudFile/src/Services/yandex_service.cpp index 3e5e63440b..cffe82caa2 100644 --- a/plugins/CloudFile/src/Services/yandex_service.cpp +++ b/plugins/CloudFile/src/Services/yandex_service.cpp @@ -218,71 +218,57 @@ auto CYandexService::CreateSharedLink(const std::string &path) return root["public_url"].as_string(); } -UINT CYandexService::Upload(FileTransferParam *ftp) +void CYandexService::Upload(FileTransferParam *ftp) { - try { - if (!IsLoggedIn()) - Login(); + std::string serverFolder = T2Utf(ftp->GetServerDirectory()); + if (!serverFolder.empty()) { + auto path = PreparePath(serverFolder); + CreateFolder(path); - if (!IsLoggedIn()) { - ftp->SetStatus(ACKRESULT_FAILED); - return ACKRESULT_FAILED; - } - - if (ftp->IsFolder()) { - T2Utf folderName(ftp->GetFolderName()); - - auto path = PreparePath(folderName); - CreateFolder(path); + auto link = CreateSharedLink(path); + ftp->AddSharedLink(link.c_str()); + } - auto link = CreateSharedLink(path); - ftp->AddSharedLink(link.c_str()); - } + ftp->FirstFile(); + do + { + std::string fileName = T2Utf(ftp->GetCurrentRelativeFilePath()); + uint64_t fileSize = ftp->GetCurrentFileSize(); - ftp->FirstFile(); - do - { - T2Utf fileName(ftp->GetCurrentRelativeFilePath()); - uint64_t fileSize = ftp->GetCurrentFileSize(); + size_t chunkSize = ftp->GetCurrentFileChunkSize(); + mir_ptr<char> chunk((char*)mir_calloc(chunkSize)); - auto path = PreparePath(fileName); - auto uploadUri = CreateUploadSession(path); + std::string path; + if (!serverFolder.empty()) + path = "/" + serverFolder + "/" + fileName; + else + path = PreparePath(fileName); - size_t chunkSize = ftp->GetCurrentFileChunkSize(); - mir_ptr<char>chunk((char*)mir_calloc(chunkSize)); + auto uploadUri = CreateUploadSession(path); - if (chunkSize == fileSize) { + if (chunkSize == fileSize) { + ftp->CheckCurrentFile(); + size_t size = ftp->ReadCurrentFile(chunk, chunkSize); + UploadFile(uploadUri, chunk, size); + ftp->Progress(size); + } + else { + uint64_t offset = 0; + double chunkCount = ceil(double(fileSize) / chunkSize); + for (size_t i = 0; i < chunkCount; i++) { ftp->CheckCurrentFile(); size_t size = ftp->ReadCurrentFile(chunk, chunkSize); - UploadFile(uploadUri, chunk, size); + UploadFileChunk(uploadUri, chunk, size, offset, fileSize); + offset += size; ftp->Progress(size); } - else { - uint64_t offset = 0; - double chunkCount = ceil(double(fileSize) / chunkSize); - for (size_t i = 0; i < chunkCount; i++) { - ftp->CheckCurrentFile(); - size_t size = ftp->ReadCurrentFile(chunk, chunkSize); - UploadFileChunk(uploadUri, chunk, size, offset, fileSize); - offset += size; - ftp->Progress(size); - } - } - - if (!ftp->IsFolder()) { - auto link = CreateSharedLink(path); - ftp->AddSharedLink(link.c_str()); - } - } while (ftp->NextFile()); - } - catch (Exception &ex) { - debugLogA("%s: %s", GetAccountName(), ex.what()); - ftp->SetStatus(ACKRESULT_FAILED); - return ACKRESULT_FAILED; - } + } - ftp->SetStatus(ACKRESULT_SUCCESS); - return ACKRESULT_SUCCESS; + if (!ftp->IsCurrentFileInSubDirectory()) { + auto link = CreateSharedLink(path); + ftp->AddSharedLink(link.c_str()); + } + } while (ftp->NextFile()); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -297,4 +283,4 @@ struct CMPluginYandex : public CMPluginBase RegisterProtocol(PROTOTYPE_PROTOWITHACCS, (pfnInitProto)CYandexService::Init, (pfnUninitProto)CYandexService::UnInit); } } - g_pluginYandex; +g_pluginYandex; |