From 554b4a978d65027ca48b1c0fba3f863666b70e25 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 28 Jun 2018 14:15:30 +0200 Subject: [PATCH] Load shared folders in the store --- www/common/outer/async-store.js | 69 +++++++++++++++++++++++++++++++++ www/common/userObject.js | 1 + 2 files changed, 70 insertions(+) diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 52c0efb9c..01d2bd62b 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -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 Store.userObjectCommand = function (clientId, cmdData, cb) { if (!cmdData || !cmdData.cmd) { return; } @@ -1331,6 +1386,20 @@ define([ /////////////////////// 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 proxy = store.proxy; var userObject = store.userObject = UserObject.init(proxy.drive, { diff --git a/www/common/userObject.js b/www/common/userObject.js index fb39eb484..0042d5d57 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -13,6 +13,7 @@ define([ var UNSORTED = module.UNSORTED = "unsorted"; var TRASH = module.TRASH = "trash"; var TEMPLATE = module.TEMPLATE = "template"; + var SHARED_FOLDERS = module.SHARED_FOLDERS = "sharedFolders"; module.init = function (files, config) { var exp = {};