Display a shared folder in the drive
parent
0c9dfc1fb5
commit
e0cc1a6eb6
|
@ -83,6 +83,11 @@ define([
|
|||
cb(obj);
|
||||
});
|
||||
};
|
||||
common.getSharedFolder = function (id, cb) {
|
||||
postMessage("GET_SHARED_FOLDER", id, function (obj) {
|
||||
cb(obj);
|
||||
});
|
||||
};
|
||||
// Settings and ready
|
||||
common.mergeAnonDrive = function (cb) {
|
||||
var data = {
|
||||
|
|
|
@ -38,7 +38,7 @@ define([
|
|||
Realtime.whenRealtimeSyncs(store.realtime, waitFor());
|
||||
if (store.sharedFolders) {
|
||||
for (var k in store.sharedFolders) {
|
||||
Realtime.whenRealtimeSync(store.sharedFolders[k].realtime, waitFor());
|
||||
Realtime.whenRealtimeSyncs(store.sharedFolders[k].realtime, waitFor());
|
||||
}
|
||||
}
|
||||
}).nThen(function () { cb(); });
|
||||
|
@ -61,6 +61,13 @@ define([
|
|||
onSync(cb);
|
||||
};
|
||||
|
||||
Store.getSharedFolder = function (clientId, id, cb) {
|
||||
if (store.manager.folders[id]) {
|
||||
return void cb(store.manager.folders[id].proxy);
|
||||
}
|
||||
cb({});
|
||||
};
|
||||
|
||||
Store.hasSigningKeys = function () {
|
||||
if (!store.proxy) { return; }
|
||||
return typeof(store.proxy.edPrivate) === 'string' &&
|
||||
|
@ -1166,7 +1173,7 @@ define([
|
|||
var id;
|
||||
nThen(function (waitFor) {
|
||||
// TODO XXX get the folder data (href, title, ...)
|
||||
var folderData = {};
|
||||
var folderData = data.folderData || {};
|
||||
// 1. add the shared folder to our list of shared folders
|
||||
store.userObject.pushSharedFolder(folderData, waitFor(function (err, folderId) {
|
||||
if (err) {
|
||||
|
@ -1177,6 +1184,7 @@ define([
|
|||
}));
|
||||
}).nThen(function (waitFor) {
|
||||
// 2a. add the shared folder to the path in our drive
|
||||
console.log('adding');
|
||||
store.userObject.add(id, path);
|
||||
onSync(waitFor());
|
||||
|
||||
|
@ -1189,6 +1197,23 @@ define([
|
|||
cb();
|
||||
});
|
||||
};
|
||||
store.createSharedFolder = function () {
|
||||
// XXX
|
||||
var hash = Hash.createRandomHash('folder');
|
||||
var href = '/folder/#' + hash;
|
||||
var secret = Hash.getSecrets('folder', hash);
|
||||
Store.addSharedFolder(null, {
|
||||
path: ['root'],
|
||||
folderData: {
|
||||
href: href,
|
||||
roHref: '/folder/#' + Hash.getViewHashFromKeys(secret),
|
||||
channel: secret.channel,
|
||||
title: "Test",
|
||||
}
|
||||
}, function () {
|
||||
console.log('done');
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// Drive
|
||||
|
|
|
@ -52,6 +52,7 @@ define([
|
|||
GET_PAD_DATA: Store.getPadData,
|
||||
GET_STRONGER_HASH: Store.getStrongerHash,
|
||||
INCREMENT_TEMPLATE_USE: Store.incrementTemplateUse,
|
||||
GET_SHARED_FOLDER: Store.getSharedFolder,
|
||||
// Messaging
|
||||
INVITE_FROM_USERLIST: Store.inviteFromUserlist,
|
||||
ADD_DIRECT_MESSAGE_HANDLERS: Store.addDirectMessageHandlers,
|
||||
|
|
|
@ -69,6 +69,23 @@ define([
|
|||
});
|
||||
};
|
||||
|
||||
exp.pushSharedFolder = function (data, cb) {
|
||||
if (typeof cb !== "function") { cb = function () {}; }
|
||||
var todo = function () {
|
||||
var id = Util.createRandomInteger();
|
||||
files[SHARED_FOLDERS][id] = data;
|
||||
cb(null, id);
|
||||
};
|
||||
if (!loggedIn || !AppConfig.enablePinning || config.testMode) {
|
||||
return void cb("EAUTH");
|
||||
}
|
||||
if (!pinPads) { return void cb('EAUTH'); }
|
||||
pinPads([data.channel], function (obj) {
|
||||
if (obj && obj.error) { return void cb(obj.error); }
|
||||
todo();
|
||||
});
|
||||
};
|
||||
|
||||
// FILES DATA
|
||||
var spliceFileData = function (id) {
|
||||
delete files[FILES_DATA][id];
|
||||
|
@ -191,6 +208,7 @@ define([
|
|||
|
||||
var toRemove = [];
|
||||
Object.keys(data).forEach(function (id) {
|
||||
id = Number(id);
|
||||
// Find and maybe update existing pads with the same channel id
|
||||
var d = data[id];
|
||||
var found = false;
|
||||
|
@ -332,9 +350,9 @@ define([
|
|||
};
|
||||
|
||||
exp.add = function (id, path) {
|
||||
// TODO WW
|
||||
if (!loggedIn && !config.testMode) { return; }
|
||||
var data = files[FILES_DATA][id];
|
||||
id = Number(id);
|
||||
var data = files[FILES_DATA][id] || files[SHARED_FOLDERS][id];
|
||||
if (!data || typeof(data) !== "object") { return; }
|
||||
var newPath = path, parentEl;
|
||||
if (path && !Array.isArray(path)) {
|
||||
|
@ -438,7 +456,6 @@ define([
|
|||
});
|
||||
delete files[OLD_FILES_DATA];
|
||||
delete files.migrate;
|
||||
console.log('done');
|
||||
todo();
|
||||
};
|
||||
if (exp.rt) {
|
||||
|
@ -581,7 +598,7 @@ define([
|
|||
});
|
||||
};
|
||||
var fixFilesData = function () {
|
||||
if (typeof files[FILES_DATA] !== "object") { debug("OLD_FILES_DATA was not an object"); files[FILES_DATA] = {}; }
|
||||
if (typeof files[FILES_DATA] !== "object") { debug("FILES_DATA was not an object"); files[FILES_DATA] = {}; }
|
||||
var fd = files[FILES_DATA];
|
||||
var rootFiles = exp.getFiles([ROOT, TRASH, 'hrefArray']);
|
||||
var root = exp.find([ROOT]);
|
||||
|
@ -649,7 +666,8 @@ define([
|
|||
secret = Hash.getSecrets(parsed.type, parsed.hash, el.password);
|
||||
}
|
||||
el.channel = secret.channel;
|
||||
console.log('Adding missing channel in filesData ', el.channel);
|
||||
console.log(el);
|
||||
debug('Adding missing channel in filesData ', el.channel);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
|
|
@ -7,17 +7,20 @@ define([
|
|||
|
||||
var getConfig = function (Env) {
|
||||
var cfg = {};
|
||||
for (var k in Env.cfg) { cfg[k] = Env[k]; }
|
||||
for (var k in Env.cfg) { cfg[k] = Env.cfg[k]; }
|
||||
return cfg;
|
||||
};
|
||||
|
||||
// Add a shared folder to the list
|
||||
var addProxy = function (Env, id, proxy, leave) {
|
||||
var cfg = getConfig();
|
||||
var cfg = getConfig(Env);
|
||||
cfg.sharedFolder = true;
|
||||
cfg.id = id;
|
||||
var userObject = UserObject.init(proxy, Env.cfg);
|
||||
userObject.fixFiles();
|
||||
var userObject = UserObject.init(proxy, cfg);
|
||||
if (userObject.fixFiles) {
|
||||
// Only in outer
|
||||
userObject.fixFiles();
|
||||
}
|
||||
Env.folders[id] = {
|
||||
proxy: proxy,
|
||||
userObject: userObject,
|
||||
|
@ -98,7 +101,9 @@ define([
|
|||
}
|
||||
var current;
|
||||
var uo = Env.user.userObject;
|
||||
for (var i=2; i<=path.length; i++) {
|
||||
// We don't need to check the last element of the path because we only need to split it
|
||||
// when the path contains an element inside the shared folder
|
||||
for (var i=2; i<path.length; i++) {
|
||||
current = uo.find(path.slice(0,i));
|
||||
if (uo.isSharedFolder(current)) {
|
||||
res = {
|
||||
|
@ -193,13 +198,21 @@ define([
|
|||
// Copy the elements to the new location
|
||||
var toCopy = _getCopyFromPaths(resolved.main, Env.user.userObject);
|
||||
var newUserObject = newResolved.userObject;
|
||||
newUserObject.copyFromOtherDrive(newResolved.path, toCopy.el, toCopy.data);
|
||||
var ownedPads = [];
|
||||
toCopy.forEach(function (obj) {
|
||||
newUserObject.copyFromOtherDrive(newResolved.path, obj.el, obj.data);
|
||||
var _owned = Object.keys(obj.data).filter(function (id) {
|
||||
var owners = obj.data[id].owners;
|
||||
return Array.isArray(owners) && owners.indexOf(Env.edPublic) !== -1;
|
||||
});
|
||||
Array.prototype.push.apply(ownedPads, _owned);
|
||||
});
|
||||
|
||||
// Filter owned pads so that we won't remove them from our drive
|
||||
var toRemove = resolved.main.slice();
|
||||
toRemove.filter(function (id) {
|
||||
var owners = Env.user.userObject.getFileData(id).owners;
|
||||
return !Array.isArray(owners) || owners.indexOf(Env.edPublic) === -1;
|
||||
var rootPath = resolved.main[0].slice();
|
||||
rootPath.pop();
|
||||
ownedPads = Util.deduplicateString(ownedPads);
|
||||
ownedPads.forEach(function (id) {
|
||||
Env.user.userObject.add(Number(id), rootPath);
|
||||
});
|
||||
|
||||
// Remove the elements from the old location (without unpinning)
|
||||
|
@ -222,7 +235,9 @@ define([
|
|||
|
||||
// Copy the elements to the new location
|
||||
var toCopy = _getCopyFromPaths(paths, uoFrom);
|
||||
uoTo.copyFromOtherDrive(newResolved.path, toCopy.el, toCopy.data);
|
||||
toCopy.forEach(function (obj) {
|
||||
uoTo.copyFromOtherDrive(newResolved.path, obj.el, obj.data);
|
||||
});
|
||||
|
||||
// Remove the elements from the old location (without unpinning)
|
||||
uoFrom.delete(paths, waitFor(), false, false, true);
|
||||
|
@ -409,16 +424,18 @@ define([
|
|||
}
|
||||
};
|
||||
}
|
||||
return function (fileId) {
|
||||
var data = userObject.getFileData(fileId);
|
||||
// Don't pin pads owned by someone else
|
||||
if (Array.isArray(data.owners) && data.owners.length &&
|
||||
data.owners.indexOf(edPublic) === -1) { return; }
|
||||
// Don't push duplicates
|
||||
if (result.indexOf(data.channel) === -1) {
|
||||
result.push(data.channel);
|
||||
}
|
||||
};
|
||||
if (type === "pin") {
|
||||
return function (fileId) {
|
||||
var data = userObject.getFileData(fileId);
|
||||
// Don't pin pads owned by someone else
|
||||
if (Array.isArray(data.owners) && data.owners.length &&
|
||||
data.owners.indexOf(edPublic) === -1) { return; }
|
||||
// Don't push duplicates
|
||||
if (result.indexOf(data.channel) === -1) {
|
||||
result.push(data.channel);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// Get the list of user objects
|
||||
|
@ -429,6 +446,13 @@ define([
|
|||
files.forEach(addChannel(uo));
|
||||
});
|
||||
|
||||
if (type === "pin") {
|
||||
var sfChannels = Object.keys(Env.folders).map(function (fId) {
|
||||
return Env.user.proxy[UserObject.SHARED_FOLDERS][fId].channel;
|
||||
});
|
||||
Array.prototype.push.apply(result, sfChannels);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
|
@ -574,7 +598,7 @@ define([
|
|||
|
||||
var find = function (Env, path) {
|
||||
var resolved = _resolvePath(Env, path);
|
||||
return resolved.userObject.find(path);
|
||||
return resolved.userObject.find(resolved.path);
|
||||
};
|
||||
|
||||
var getTitle = function (Env, id, type) {
|
||||
|
@ -660,7 +684,14 @@ define([
|
|||
var isFolder = function (Env, el) {
|
||||
return Env.user.userObject.isFolder(el);
|
||||
};
|
||||
var isSharedFolder = function (Env, el) {
|
||||
return Env.user.userObject.isSharedFolder(el);
|
||||
};
|
||||
var isFolderEmpty = function (Env, el) {
|
||||
if (Env.folders[el]) {
|
||||
var uo = Env.folders[el].userObject;
|
||||
return uo.isFolderEmpty(uo.find[uo.ROOT]);
|
||||
}
|
||||
return Env.user.userObject.isFolderEmpty(el);
|
||||
};
|
||||
var isPathIn = function (Env, path, categories) {
|
||||
|
@ -676,9 +707,17 @@ define([
|
|||
return Env.user.userObject.comparePath(a, b);
|
||||
};
|
||||
var hasSubfolder = function (Env, el, trashRoot) {
|
||||
if (Env.folders[el]) {
|
||||
var uo = Env.folders[el].userObject;
|
||||
return uo.hasSubfolder(uo.find[uo.ROOT]);
|
||||
}
|
||||
return Env.user.userObject.hasSubfolder(el, trashRoot);
|
||||
};
|
||||
var hasFile = function (Env, el, trashRoot) {
|
||||
if (Env.folders[el]) {
|
||||
var uo = Env.folders[el].userObject;
|
||||
return uo.hasFile(uo.find[uo.ROOT]);
|
||||
}
|
||||
return Env.user.userObject.hasFile(el, trashRoot);
|
||||
};
|
||||
|
||||
|
@ -726,6 +765,7 @@ define([
|
|||
// Generic
|
||||
isFile: callWithEnv(isFile),
|
||||
isFolder: callWithEnv(isFolder),
|
||||
isSharedFolder: callWithEnv(isSharedFolder),
|
||||
isFolderEmpty: callWithEnv(isFolderEmpty),
|
||||
isPathIn: callWithEnv(isPathIn),
|
||||
isSubpath: callWithEnv(isSubpath),
|
||||
|
|
|
@ -31,7 +31,7 @@ define([
|
|||
exp.TEMPLATE = TEMPLATE;
|
||||
exp.SHARED_FOLDERS = SHARED_FOLDERS;
|
||||
|
||||
exp.sharedFolder = config.sharedFolder;
|
||||
var sharedFolder = exp.sharedFolder = config.sharedFolder;
|
||||
exp.id = config.id;
|
||||
|
||||
// Logging
|
||||
|
@ -71,7 +71,12 @@ define([
|
|||
|
||||
var compareFiles = function (fileA, fileB) { return fileA === fileB; };
|
||||
|
||||
var isSharedFolder = exp.isSharedFolder = function (element) {
|
||||
if (sharedFolder) { return false; } // No recursive shared folders
|
||||
return Boolean(files[SHARED_FOLDERS][element]);
|
||||
};
|
||||
var isFile = exp.isFile = function (element, allowStr) {
|
||||
if (isSharedFolder(element)) { return false; }
|
||||
return typeof(element) === "number" ||
|
||||
((typeof(files[OLD_FILES_DATA]) !== "undefined" || allowStr)
|
||||
&& typeof(element) === "string");
|
||||
|
@ -84,15 +89,12 @@ define([
|
|||
};
|
||||
|
||||
var isFolder = exp.isFolder = function (element) {
|
||||
return typeof(element) === "object";
|
||||
return typeof(element) === "object" || isSharedFolder(element);
|
||||
};
|
||||
exp.isFolderEmpty = function (element) {
|
||||
if (!isFolder(element)) { return false; }
|
||||
return Object.keys(element).length === 0;
|
||||
};
|
||||
exp.isSharedFolder = function (element) {
|
||||
return Boolean(files[SHARED_FOLDERS][element]);
|
||||
};
|
||||
|
||||
exp.hasSubfolder = function (element, trashRoot) {
|
||||
if (!isFolder(element)) { return false; }
|
||||
|
@ -311,7 +313,7 @@ define([
|
|||
}
|
||||
};
|
||||
|
||||
if (isFile(root)) {
|
||||
if (isFile(root) || isSharedFolder(root)) {
|
||||
if (compareFiles(file, root)) {
|
||||
if (paths.indexOf(path) === -1) {
|
||||
paths.push(path);
|
||||
|
@ -331,6 +333,7 @@ define([
|
|||
return _findFileInRoot([ROOT], file);
|
||||
};
|
||||
var _findFileInHrefArray = function (rootName, file) {
|
||||
if (sharedFolder) { return []; }
|
||||
if (!files[rootName]) { return []; }
|
||||
var unsorted = files[rootName].slice();
|
||||
var ret = [];
|
||||
|
@ -341,6 +344,7 @@ define([
|
|||
return ret;
|
||||
};
|
||||
var _findFileInTrash = function (path, file) {
|
||||
if (sharedFolder) { return []; }
|
||||
var root = find(path);
|
||||
var paths = [];
|
||||
var addPaths = function (p) {
|
||||
|
@ -602,7 +606,7 @@ define([
|
|||
var element = find(path);
|
||||
|
||||
// Folders
|
||||
if (isFolder(element)) {
|
||||
if (isFolder(element) && !isSharedFolder(element)) {
|
||||
var parentPath = path.slice();
|
||||
var oldName = parentPath.pop();
|
||||
if (!newName || !newName.trim() || oldName === newName) { return; }
|
||||
|
@ -617,8 +621,13 @@ define([
|
|||
return;
|
||||
}
|
||||
|
||||
// Files
|
||||
var data = files[FILES_DATA][element];
|
||||
// Files or Shared folder
|
||||
var data;
|
||||
if (isSharedFolder(element)) {
|
||||
data = files[SHARED_FOLDERS][element];
|
||||
} else {
|
||||
data = files[FILES_DATA][element];
|
||||
}
|
||||
if (!data) { return; }
|
||||
if (!newName || newName.trim() === "") {
|
||||
delete data.filename;
|
||||
|
|
|
@ -210,6 +210,23 @@ define([
|
|||
for (var k in objRef) { delete objRef[k]; }
|
||||
$.extend(true, objRef, objToCopy);
|
||||
};
|
||||
var updateSharedFolders = function (sframeChan, drive, folders, cb) {
|
||||
if (!drive || !drive.sharedFolders) {
|
||||
return void cb();
|
||||
}
|
||||
nThen(function (waitFor) {
|
||||
Object.keys(drive.sharedFolders).forEach(function (fId) {
|
||||
sframeChan.query('Q_DRIVE_GETOBJECT', {
|
||||
sharedFolder: fId
|
||||
}, waitFor(function (err, newObj) {
|
||||
folders[fId] = folders[fId] || {};
|
||||
copyObjectValue(folders[fId], newObj);
|
||||
}));
|
||||
});
|
||||
}).nThen(function () {
|
||||
cb();
|
||||
});
|
||||
};
|
||||
var updateObject = function (sframeChan, obj, cb) {
|
||||
sframeChan.query('Q_DRIVE_GETOBJECT', null, function (err, newObj) {
|
||||
copyObjectValue(obj, newObj);
|
||||
|
@ -314,15 +331,11 @@ define([
|
|||
config.loggedIn = APP.loggedIn;
|
||||
config.sframeChan = sframeChan;
|
||||
|
||||
|
||||
var manager = ProxyManager.createInner(files, sframeChan, config);
|
||||
|
||||
Object.keys(folders).forEach(function (id) {
|
||||
var f = folders[id];
|
||||
// f.data => metadata (href, title, password...)
|
||||
// f.proxy => listmap
|
||||
// f.id => id?
|
||||
manager.addProxy(id, f.proxy);
|
||||
manager.addProxy(id, f);
|
||||
});
|
||||
|
||||
var $tree = APP.$tree = $("#cp-app-drive-tree");
|
||||
|
@ -1166,7 +1179,10 @@ define([
|
|||
var $target = $(target);
|
||||
var $el = findDataHolder($target);
|
||||
var newPath = $el.data('path');
|
||||
if ((!newPath || manager.isFile(manager.find(newPath)))
|
||||
var dropEl = newPath && manager.find(newPath);
|
||||
if (newPath && manager.isSharedFolder(dropEl)) {
|
||||
newPath.push(manager.user.userObject.ROOT);
|
||||
} else if ((!newPath || manager.isFile(dropEl))
|
||||
&& $target.parents('#cp-app-drive-content')) {
|
||||
newPath = currentPath;
|
||||
}
|
||||
|
@ -2293,6 +2309,11 @@ define([
|
|||
var isTags = path[0] === TAGS;
|
||||
|
||||
var root = isVirtual ? undefined : manager.find(path);
|
||||
if (manager.isSharedFolder(root)) {
|
||||
path.push(manager.user.userObject.ROOT);
|
||||
root = manager.find(path);
|
||||
if (!root) { return; }
|
||||
}
|
||||
if (!isVirtual && typeof(root) === "undefined") {
|
||||
log(Messages.fm_unknownFolderError);
|
||||
debug("Unable to locate the selected directory: ", path);
|
||||
|
@ -2434,7 +2455,9 @@ define([
|
|||
}
|
||||
updateObject(sframeChan, proxy, function () {
|
||||
copyObjectValue(files, proxy.drive);
|
||||
_displayDirectory(path, force);
|
||||
updateSharedFolders(sframeChan, files, folders, function () {
|
||||
_displayDirectory(path, force);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -3058,8 +3081,9 @@ define([
|
|||
};*/
|
||||
|
||||
var sframeChan = common.getSframeChannel();
|
||||
updateObject(sframeChan, proxy, waitFor());
|
||||
// XXX Load shared folders
|
||||
updateObject(sframeChan, proxy, waitFor(function () {
|
||||
updateSharedFolders(sframeChan, proxy.drive, folders, waitFor());
|
||||
}));
|
||||
}).nThen(function () {
|
||||
var sframeChan = common.getSframeChannel();
|
||||
var metadataMgr = common.getMetadataMgr();
|
||||
|
|
|
@ -53,6 +53,12 @@ define([
|
|||
Cryptpad.userObjectCommand(data, cb);
|
||||
});
|
||||
sframeChan.on('Q_DRIVE_GETOBJECT', function (data, cb) {
|
||||
if (data && data.sharedFolder) {
|
||||
Cryptpad.getSharedFolder(data.sharedFolder, function (obj) {
|
||||
cb(obj);
|
||||
});
|
||||
return;
|
||||
}
|
||||
Cryptpad.getUserObject(function (obj) {
|
||||
cb(obj);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue