Load shared folders in the store

pull/1/head
yflory 7 years ago
parent 6d94f6ce21
commit 554b4a978d

@ -1183,6 +1183,61 @@ define([
}])); }]));
}; };
// SHARED FOLDERS
var loadSharedFolder = function (id, data) {
var parsed = Hash.parsePadUrl(data.href);
var secret = Hash.getSecrets('folder', parsed.hash, data.password);
var listmapConfig = {
data: {},
websocketURL: NetConfig.getWebsocketURL(),
channel: secret.channel,
readOnly: false,
validateKey: secret.keys.validateKey || undefined,
crypto: Crypto.createEncryptor(secret.keys),
userName: 'sharedFolder',
logLevel: 1,
ChainPad: ChainPad,
classic: true,
};
var rt = Listmap.create(listmapConfig);
store.sharedFolders[id] = rt;
return rt;
};
Store.addSharedFolder = function (clientId, data, cb) {
var path = data.path;
var href = data.href;
var id;
nThen(function (waitFor) {
// TODO
var folderData = {};
// 1. add the shared folder to our list of shared folders
store.userObject.pushSharedFolder(folderData, waitFor(function (err, folderId) {
if (err) {
waitFor.abort();
return void cb(err);
}
id = folderId;
}));
nThen(function (waitFor) {
// 2a. add the shared folder to the path in our drive
store.userObject.add(id, path);
onSync(waitFor());
// 2b. load the proxy
var rt = loadSharedFolder(folderId, data);
rt.on('ready', waitFor(function () {
// TODO
// "fixFiles"
}));
}).nThen(function () {
sendDriveEvent('DRIVE_CHANGE', {
path: ['drive'].concat(path)
}, clientId);
cb();
});
};
// Drive // Drive
Store.userObjectCommand = function (clientId, cmdData, cb) { Store.userObjectCommand = function (clientId, cmdData, cb) {
if (!cmdData || !cmdData.cmd) { return; } if (!cmdData || !cmdData.cmd) { return; }
@ -1331,6 +1386,20 @@ define([
/////////////////////// Init ///////////////////////////////////// /////////////////////// Init /////////////////////////////////////
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
var loadSharedFolders = function (waitFor) {
// TODO
store.sharedFolders = {};
var shared = Util.find(store.proxy, ['drive', UserObject.SHARED_FOLDERS]) || {};
Object.keys(shared).forEach(function (id) {
var sf = shared[id];
var rt = loadSharedFolder(id, sf);
rt.on('ready', waitFor(function () {
// TODO
// "fixFiles"
}));
});
};
var onReady = function (clientId, returned, cb) { var onReady = function (clientId, returned, cb) {
var proxy = store.proxy; var proxy = store.proxy;
var userObject = store.userObject = UserObject.init(proxy.drive, { var userObject = store.userObject = UserObject.init(proxy.drive, {

@ -13,6 +13,7 @@ define([
var UNSORTED = module.UNSORTED = "unsorted"; var UNSORTED = module.UNSORTED = "unsorted";
var TRASH = module.TRASH = "trash"; var TRASH = module.TRASH = "trash";
var TEMPLATE = module.TEMPLATE = "template"; var TEMPLATE = module.TEMPLATE = "template";
var SHARED_FOLDERS = module.SHARED_FOLDERS = "sharedFolders";
module.init = function (files, config) { module.init = function (files, config) {
var exp = {}; var exp = {};

Loading…
Cancel
Save