diff --git a/www/common/drive-ui.js b/www/common/drive-ui.js index f83f445c0..e9b75f66d 100644 --- a/www/common/drive-ui.js +++ b/www/common/drive-ui.js @@ -4025,9 +4025,10 @@ define([ var header7, header28, headerOld; var i = 0; var channels = []; + var toShow = []; if (typeFilter) { - var ids = filesList.map(function (arr) { return arr[0]; }); + let ids = filesList.map(function (arr) { return arr[0]; }); var idsFilter = filterPads(ids, typeFilter, false, true); filesList = filesList.filter(function (arr) { return (idsFilter.indexOf(arr[0]) !== -1); @@ -4046,15 +4047,18 @@ define([ return true; } - var paths = manager.findFile(id); - if (!paths.length) { return; } - var path = paths[0]; - if (manager.isPathIn(path, [TRASH])) { return; } - if (!file.channel) { file.channel = id; } if (channels.indexOf(file.channel) !== -1) { return; } channels.push(file.channel); + toShow.push({id, file}); + i++; + }); + let ids = toShow.map(obj => { return obj.id }); + var allPaths = manager.findFiles(ids); + toShow.forEach(obj => { + let file = obj.file; + let id = obj.id; if (!header7 && file.atime < last1) { $list.append(h('li.cp-app-drive-element-separator', h('span', Messages.drive_active7Days))); header7 = true; @@ -4078,6 +4082,12 @@ define([ var $element = $('
  • ', { 'class': 'cp-app-drive-element cp-app-drive-element-notrash cp-app-drive-element-file cp-app-drive-element-row' + roClass, });*/ + var paths = allPaths[id]; + if (paths.every(path => { + return manager.isPathIn(path, [TRASH]) + })) { return; } + var path = paths[0]; + var parentPath = path.slice(); var key = parentPath.pop(); var root = manager.find(parentPath); @@ -4085,7 +4095,6 @@ define([ $element.off('contextmenu').contextmenu(openContextMenu('default')); $element.data('context', 'default'); $list.append($element); - i++; }); }; diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index 509e91a3a..d2704c16b 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -235,11 +235,25 @@ define([ var findFile = function (Env, id) { var ret = []; var userObjects = _getUserObjects(Env); + let mainRes = {}; userObjects.forEach(function (uo) { - var fPath = _getUserObjectPath(Env, uo); - var results = uo.findFile(id); - if (fPath) { + var fId = Number(uo.id); + let results; + if (!fId) { + // Main drive: get the paths of all the SF + // in addition to the paths of the requested file + let ids = [id]; + let fIds = userObjects.map(uo => { + return +uo.id; + }).filter(Boolean); + Array.prototype.push.apply(ids, fIds); + mainRes = uo.findFiles(ids); // Store paths of each SF + results = mainRes[id]; // Paths of requested file + } else { + results = uo.findFile(id); // This is a shared folder, we have to fix the paths in the results + let fPath = (mainRes[fId] || [])[0]; + if (!fPath) { return; } // Can't search into this sf results.forEach(function (p) { Array.prototype.unshift.apply(p, fPath); }); @@ -249,6 +263,41 @@ define([ }); return ret; }; + var findFiles = function (Env, ids) { + var ret = {}; + var userObjects = _getUserObjects(Env); + let mainRes = {}; + userObjects.forEach(function (uo) { + //var fPath = _getUserObjectPath(Env, uo); + var fId = Number(uo.id); + if (!uo.id) { + let fIds = userObjects.map(uo => { + return +uo.id; + }).filter(Boolean); + Array.prototype.push.apply(ids, fIds); + } + var results = uo.findFiles(ids); + if (!uo.id) { mainRes = results; } + //console.error(results); + if (fId) { + // This is a shared folder, we have to fix the paths in the results + let fPath = (mainRes[fId] || [])[0]; + if (!fPath) { return; } // Can't search into this sf + Object.keys(results).forEach(file => { + results[file].forEach(p => { + Array.prototype.unshift.apply(p, fPath); + }); + }); + } + // Push the results from this proxy + Object.keys(results).forEach(file => { + ret[file] ||= []; + Array.prototype.push.apply(ret[file], results[file]); + }); + }); + return ret; + }; + // Returns file IDs corresponding to the provided channels var _findChannels = function (Env, channels, onlyMain) { @@ -1753,6 +1802,7 @@ define([ getOwnedPads: callWithEnv(getOwnedPads), getTagsList: callWithEnv(getTagsList), findFile: callWithEnv(findFile), + findFiles: callWithEnv(findFiles), findChannels: callWithEnv(findChannels), getSharedFolderData: callWithEnv(getSharedFolderData), getFolderData: callWithEnv(getFolderData), diff --git a/www/common/userObject.js b/www/common/userObject.js index 14a60a5d4..62f80c9cc 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -573,56 +573,65 @@ define([ }; // SEARCH - var _findFileInRoot = function (path, file) { + var _findFileInRoot = function (path, files) { if (!isPathIn(path, [ROOT, TRASH])) { return []; } - var paths = []; + files = Array.isArray(files) ? files : [files]; + var paths = {}; var root = find(path); var addPaths = function (p) { - if (paths.indexOf(p) === -1) { - paths.push(p); - } + Object.keys(p).forEach(file => { + paths[file] ||= []; + Array.prototype.push.apply(paths[file], p[file]); + }); }; if (isFile(root) || isSharedFolder(root)) { - if (compareFiles(file, root)) { - if (paths.indexOf(path) === -1) { - paths.push(path); + files.some(file => { + if (compareFiles(file, root)) { + paths[file] ||= []; + paths[file].push(path); } - } + }); return paths; } if (isFolder(root)) { for (var e in root) { - var nPath = path.slice(); + let nPath = path.slice(); nPath.push(e); - _findFileInRoot(nPath, file).forEach(addPaths); + addPaths(_findFileInRoot(nPath, files)); } } return paths; }; - exp.findFileInRoot = function (file) { - return _findFileInRoot([ROOT], file); + /* + exp.findFileInRoot = function (files) { + return _findFileInRoot([ROOT], files); }; - var _findFileInHrefArray = function (rootName, file) { - if (sharedFolder) { return []; } - if (!files[rootName]) { return []; } + */ + var _findFileInHrefArray = function (rootName, toFind) { + if (sharedFolder) { return {}; } + if (!files[rootName]) { return {}; } var unsorted = files[rootName].slice(); - var ret = []; + var ret = {}; var i = -1; - while ((i = unsorted.indexOf(file, i+1)) !== -1){ - ret.push([rootName, i]); - } + toFind.forEach(file => { + while ((i = unsorted.indexOf(file, i+1)) !== -1){ + ret[file] ||= []; + ret[file].push([rootName, i]); + } + }); return ret; }; - var _findFileInTrash = function (path, file) { + var _findFileInTrash = function (path, files) { if (sharedFolder) { return []; } var root = find(path); - var paths = []; + var paths = {}; var addPaths = function (p) { - if (paths.indexOf(p) === -1) { - paths.push(p); - } + Object.keys(p).forEach(file => { + paths[file] ||= []; + Array.prototype.push.apply(paths[file], p[file]); + }); }; if (path.length === 1 && typeof(root) === 'object') { Object.keys(root).forEach(function (key) { @@ -630,7 +639,7 @@ define([ if (!Array.isArray(arr)) { return; } var nPath = path.slice(); nPath.push(key); - _findFileInTrash(nPath, file).forEach(addPaths); + addPaths(_findFileInTrash(nPath, files)); }); } if (path.length === 2) { @@ -640,24 +649,39 @@ define([ nPath.push(i); nPath.push('element'); if (isFile(el.element)) { - if (compareFiles(file, el.element)) { - addPaths(nPath); - } + files.some(file => { + if (compareFiles(file, el.element)) { + paths[file] ||= []; + paths[file].push(nPath); + } + }); return; } - _findFileInTrash(nPath, file).forEach(addPaths); + addPaths(_findFileInTrash(nPath, files)); }); } if (path.length >= 4) { - _findFileInRoot(path, file).forEach(addPaths); + addPaths(_findFileInRoot(path, files)); } return paths; }; + var findFiles = exp.findFiles = function (files) { + var rootpaths = _findFileInRoot([ROOT], files); + var templatepaths = _findFileInHrefArray(TEMPLATE, files); + var trashpaths = _findFileInTrash([TRASH], files); + let res = {}; + files.forEach(file => { res[file] = []; }); + [rootpaths, templatepaths, trashpaths].forEach(r => { + Object.keys(r).forEach(file => { + res[file] ||= []; + Array.prototype.push.apply(res[file], r[file]); + }); + }); + return res; + }; var findFile = exp.findFile = function (file) { - var rootpaths = _findFileInRoot([ROOT], file); - var templatepaths = _findFileInHrefArray(TEMPLATE, file); - var trashpaths = _findFileInTrash([TRASH], file); - return rootpaths.concat(templatepaths, trashpaths); + let res = findFiles([file]); + return res[file] || []; }; // Get drive ids of files from their channel ids