From 55f69a1f36af07a7d4bae1d56806f5f75828d66a Mon Sep 17 00:00:00 2001 From: Sergey Svistunov Date: Sun, 11 Aug 2024 19:33:22 +0300 Subject: [PATCH] Remove dead hosting userscloud.com Add support of nested folders for mega.nz --- Data/Favicons/userscloud.ico | Bin 5430 -> 0 bytes Data/Scripts/userscloud.nut | 69 ---------------------- Data/servers.xml | 5 -- Source/Core/Upload/MegaNzUploadEngine.cpp | 38 ++++++++---- 4 files changed, 27 insertions(+), 85 deletions(-) delete mode 100644 Data/Favicons/userscloud.ico delete mode 100644 Data/Scripts/userscloud.nut diff --git a/Data/Favicons/userscloud.ico b/Data/Favicons/userscloud.ico deleted file mode 100644 index d4cb9269158aa188d4d3da7e3f57561c848ae448..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5430 zcmd55-onT0x9?~a98-~F7qSdVCl*C2k~!pw_}(emz==YPd>edMYJ#Fm=^xk>snD+ zZC2&g!moxY?+fZL*7p@I)ac?D>MYgUeHT{+9xoP|N%t@`UixShBwD=ndlh<{*{J8k-Fe<7{$R<7W zx_N~L)a|_jbC(P34^N%8Bfm)9H%W3ti=VU1fHP;WiSYyb&L)Es`}SM0cB2soU+#v* z;ud3q0lOFb=$s^+NOiRMybhoL$cRsL{61d*wr)3mZFGonf!{w7leBk?VawL`xZrPk zpba)#IDX+ch~?m#3&%sBe=&&crIX_sH62W6|GduE-wcUZY9EKghdp!;)bNyj)4^X^ z+JbXm4yr+meT=`i{wne!#6@x$qQU2Pynd5WjPtG!jYq`ivoN+fae!jV6(y1F1k0fn zpY7g5k93IVIx^~`vyKQa4)8tX82P>T`%$*R7|{l4!RLEaxyy`SeshSi`qaqbQNE8H z<9>Dix|m<^9^|^$vVYe3_8ph;{SU*i+T7^r@rZQQ>ZW(+5$}2!5#V#_4$cwhk`8$8 z1-h^0TiT|DUrcAXuH1;#Yg;zk^xP0{!Qsu G;>y3dCG9l; diff --git a/Data/Scripts/userscloud.nut b/Data/Scripts/userscloud.nut deleted file mode 100644 index 22fa5f98..00000000 --- a/Data/Scripts/userscloud.nut +++ /dev/null @@ -1,69 +0,0 @@ -const BASE_HOST = "https://userscloud.com/"; - -function _getUploadURL() { - nm.doGet(BASE_HOST); - if (nm.responseCode() != 200) { - WriteLog("error", "[userscloud.com] Cannot obtain upload server address. \r\nResponse code:" + nm.responseCode()); - return ""; - } - - local doc = Document(nm.responseBody()); - local uploadURL = doc.find("#uploadfile").attr("action"); - if (uploadURL != "") { - return uploadURL; - } - WriteLog("error", "[userscloud.com] Cannot obtain upload server address from the main page."); - return ""; -} - -function UploadFile(fileName, options) { - local uploadURL = _getUploadURL(); - if (uploadURL == "") { - return 0; - } - local name = ExtractFileName(fileName); - local mime = GetFileMimeType(name); - nm.setUrl(uploadURL); - nm.addQueryParam("sess_id", ""); - nm.addQueryParam("utype", "anon"); - nm.addQueryParam("link_rcpt", ""); - nm.addQueryParam("link_pass", ""); - nm.addQueryParam("keepalive", "1"); - nm.addQueryParamFile("file_0", fileName, name, mime); - nm.doUploadMultipartData(); - - if (nm.responseCode() == 200) { - local sJSON = nm.responseBody(); - local t = ParseJSON(sJSON); - if (t != null) { - if (t[0].file_status = "Ok") { - nm.doGet(BASE_HOST + "?op=upload_result&st=OK&fn=" + nm.urlEncode(t[0].file_code)); - - if (nm.responseCode() == 200) { - local doc = Document(nm.responseBody()); - local viewURL = strip(doc.find("#tab1 textarea").text()); - local directURL = strip(doc.find("#tab5 textarea").text()); - local thumbURL = strip(doc.find("#tab6 textarea").text()); - local deleteURL = strip(doc.find("#tab4 textarea").text()); - options.setDirectUrl(directURL); - options.setViewUrl(viewURL); - options.setThumbUrl(thumbURL); - options.setDeleteUrl(deleteURL); - - if (directURL != "" || viewURL != "") { - return 1; - } else { - WriteLog("error", "[userscloud.com] Cannot obtain file links from server's response."); - } - } - - } else { - WriteLog("error", "[userscloud.com] Status: " + t.file_status); - } - } - } else { - WriteLog("error", "[userscloud.com] Failed to upload. \r\nResponse code: " + nm.responseCode()); - } - - return 0; -} \ No newline at end of file diff --git a/Data/servers.xml b/Data/servers.xml index e18040d1..bbb1662f 100644 --- a/Data/servers.xml +++ b/Data/servers.xml @@ -301,11 +301,6 @@ - - - - - diff --git a/Source/Core/Upload/MegaNzUploadEngine.cpp b/Source/Core/Upload/MegaNzUploadEngine.cpp index 25c1cb1c..55a86907 100644 --- a/Source/Core/Upload/MegaNzUploadEngine.cpp +++ b/Source/Core/Upload/MegaNzUploadEngine.cpp @@ -252,18 +252,34 @@ int CMegaNzUploadEngine::getFolderList(CFolderList& FolderList) { } folderList_ = &FolderList; if (ensureNodesFetched()) { - FolderList.AddFolder("/", "", std::string("/"), "", 0); - MegaNode *root = megaApi_->getRootNode(); - MegaNodeList *list = megaApi_->getChildren(root); - - for (int i = 0; i < list->size(); i++) { - MegaNode *node = list->get(i); - if (node->isFolder()) { - FolderList.AddFolder(node->getName(), "", std::string("/")+node->getName(), "/", 0); + std::string parentId = FolderList.parentFolder().getId(); + + if (parentId.empty()) { + FolderList.AddFolder("/", "", std::string("/"), "", 0); + } else { + MegaNode* parent = megaApi_->getNodeByPath(parentId.c_str()); + if (parent) { + MegaNodeList* list = megaApi_->getChildren(parent); + + if (list) { + for (int i = 0; i < list->size(); i++) { + MegaNode* node = list->get(i); + if (node->isFolder()) { + std::string nodeId = parentId; + + // nodeId cannot be empty at this line, so we can avoid checking for emptiness here. + if (nodeId.back() != '/') { + nodeId.append("/"); + } + nodeId += node->getName(); + FolderList.AddFolder(node->getName(), "", nodeId, parentId, 0); + } + } + } + delete list; + delete parent; } } - delete list; - delete root; } return fetchNodesSuccess_ ? 1 : 0; @@ -605,4 +621,4 @@ void MyListener::onNodesUpdate(MegaApi* api, MegaNodeList *nodes) //std::cout << "***** There are " << nodes->size() << " new or updated node/s in your account" << std::endl; } -#endif \ No newline at end of file +#endif