diff --git a/customize.dist/fsStore.js b/customize.dist/fsStore.js index 1ab788dc4..dcf36927b 100644 --- a/customize.dist/fsStore.js +++ b/customize.dist/fsStore.js @@ -39,6 +39,11 @@ define([ cb(void 0, map); }; + Store.setDrive = function (key, val, cb) { + storeObj.drive[key] = val; + cb(); + }; + var safeGet = window.safeGet = function (key) { return storeObj[key]; }; @@ -56,6 +61,10 @@ define([ cb(void 0, res); }; + Store.getDrive = function (key, cb) { + cb(void 0, storeObj.drive[key]); + }; + var safeRemove = function (key) { delete storeObj[key]; }; @@ -127,7 +136,7 @@ define([ }; var onReady = function (f, proxy, storageKey) { - filesOp = FO.init(proxy, { + filesOp = FO.init(proxy.drive, { storageKey: storageKey }); storeObj = proxy; @@ -179,10 +188,13 @@ define([ } }).on('ready', function () { if (ready) { return; } - if (!rt.proxy[Cryptpad.storageKey] || !Cryptpad.isArray(rt.proxy[Cryptpad.storageKey])) { + if (!rt.proxy.drive || typeof(rt.proxy.drive) !== 'object') { rt.proxy.drive = {}; } + var drive = rt.proxy.drive; + // Creating a new anon drive: import anon pads from localStorage + if (!drive[Cryptpad.storageKey] || !Cryptpad.isArray(drive[Cryptpad.storageKey])) { var oldStore = Cryptpad.getStore(true); oldStore.get(Cryptpad.storageKey, function (err, s) { - rt.proxy[Cryptpad.storageKey] = s; + drive[Cryptpad.storageKey] = s; onReady(f, rt.proxy, Cryptpad.storageKey); }); return; diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 9ae31a238..1daf1fe73 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -80,7 +80,7 @@ define([ var logout = common.logout = function (cb) { [ - fileHashKey, +// fileHashKey, userHashKey, ].forEach(function (k) { sessionStorage.removeItem(k); @@ -88,6 +88,9 @@ define([ delete localStorage[k]; delete sessionStorage[k]; }); + if (!localStorage[fileHashKey]) { + localStorage[fileHashKey] = common.createRandomHash(); + } if (cb) { cb(); } }; @@ -101,6 +104,11 @@ define([ return hash; }; + var isLoggedIn = common.isLoggedIn = function () { + //return typeof getStore().getLoginName() === "string"; + return typeof getUserHash() === "string"; + }; + // var isArray = function (o) { return Object.prototype.toString.call(o) === '[object Array]'; }; var isArray = common.isArray = $.isArray; @@ -444,7 +452,7 @@ define([ // STORAGE /* fetch and migrate your pad history from localStorage */ var getRecentPads = common.getRecentPads = function (cb, legacy) { - getStore(legacy).get(storageKey, function (err, recentPads) { + getStore(legacy).getDrive(storageKey, function (err, recentPads) { if (isArray(recentPads)) { cb(void 0, migrateRecentPads(recentPads)); return; @@ -456,7 +464,7 @@ define([ // STORAGE /* commit a list of pads to localStorage */ var setRecentPads = common.setRecentPads = function (pads, cb, legacy) { - getStore(legacy).set(storageKey, pads, function (err, data) { + getStore(legacy).setDrive(storageKey, pads, function (err, data) { cb(err, data); }); }; @@ -566,8 +574,11 @@ define([ if (!contains) { var data = makePad(href, name); + if (common.initialPath) { + data.owner = 1; // TODO use owner id here? + } renamed.push(data); - if (USE_FS_STORE && typeof(getStore().addPad) === "function") { + if (USE_FS_STORE && common.initialPath && typeof(getStore().addPad) === "function") { getStore().addPad(href, common.initialPath, name); } } diff --git a/www/common/fileObject.js b/www/common/fileObject.js index 7398ffc7d..4137a0f84 100644 --- a/www/common/fileObject.js +++ b/www/common/fileObject.js @@ -8,6 +8,7 @@ define([ var ROOT = "root"; var UNSORTED = "unsorted"; var FILES_DATA = "filesData"; + var ANON = "anon"; // virtual path var TRASH = "trash"; var TEMPLATE = "template"; var NEW_FOLDER_NAME = Messages.fm_newFolder; @@ -57,6 +58,9 @@ define([ var isPathInTrash = exp.isPathInTrash = function (path) { return path[0] && path[0] === TRASH; }; + var isPathInAnon = exp.isPathInAnon = function (path) { + return path[0] && path[0] === ANON; + }; var isPathInFilesData = exp.isPathInFilesData = function (path) { return path[0] && path[0] === FILES_DATA; @@ -227,6 +231,13 @@ define([ return ret; }; + /*var getAnonFiles = exp.getAnonFiles = function () { + if (!files[ANON]) { + files[ANON] = []; + } + return files[ANON].slice(); + };*///TODO + var removeFileFromRoot = function (root, href) { if (isFile(root)) { return; } for (var e in root) { @@ -688,6 +699,11 @@ define([ }); }; + var isAnonFile = exp.isAnonFile = function (file) { + var data = getFileData(file); + return !data.owner; + }; + var fixFiles = exp.fixFiles = function () { // Explore the tree and check that everything is correct: // * 'root', 'trash', 'unsorted' and 'filesData' exist and are objects @@ -709,6 +725,11 @@ define([ debug("An element in ROOT was not a folder nor a file. ", element[el]); element[el] = undefined; delete element[el]; + } else if (isFile(element[el])) { + if (isAnonFile(element[el])) { + debug("An element in ROOT was an anonymous file. ", element[el]); + delete element[el]; + } } else if (isFolder(element[el])) { fixRoot(element[el]); } @@ -721,6 +742,7 @@ define([ var addToClean = function (obj, idx) { if (typeof(obj) !== "object") { toClean.push(idx); return; } if (!isFile(obj.element) && !isFolder(obj.element)) { toClean.push(idx); return; } + if (isFile(obj.element) && isAnonFile(obj.element)) { toClean.push(idx); return; } if (!$.isArray(obj.path)) { toClean.push(idx); return; } }; for (var el in tr) { @@ -745,15 +767,12 @@ define([ var templateFiles = getTemplateFiles(); var toClean = []; us.forEach(function (el, idx) { - if (!isFile(el) || rootFiles.indexOf(el) !== -1 || templateFiles.indexOf(el) !== -1) { + if (!isFile(el) || rootFiles.indexOf(el) !== -1 || templateFiles.indexOf(el) !== -1 || isAnonFile(el)) { toClean.push(idx); } }); - toClean.forEach(function (el) { - var idx = us.indexOf(el); - if (idx !== -1) { - us.splice(idx, 1); - } + toClean.forEach(function (idx) { + us.splice(idx, 1); }); }; var fixTemplate = function () { @@ -764,36 +783,44 @@ define([ var unsortedFiles = getUnsortedFiles(); var toClean = []; us.forEach(function (el, idx) { - if (!isFile(el) || rootFiles.indexOf(el) !== -1 || unsortedFiles.indexOf(el) !== -1) { + if (!isFile(el) || rootFiles.indexOf(el) !== -1 || unsortedFiles.indexOf(el) !== -1 || isAnonFile(el)) { toClean.push(idx); } }); - toClean.forEach(function (el) { - var idx = us.indexOf(el); - if (idx !== -1) { - us.splice(idx, 1); - } + toClean.forEach(function (idx) { + us.splice(idx, 1); }); }; + /*var fixAnon = function () { + if (!$.isArray(files[ANON])) { debug("ANON was not an array"); files[FILES_DATA] = []; } + };*/// TODO var fixFilesData = function () { if (!$.isArray(files[FILES_DATA])) { debug("FILES_DATA was not an array"); files[FILES_DATA] = []; } var fd = files[FILES_DATA]; var rootFiles = getRootFiles(); var unsortedFiles = getUnsortedFiles(); + var templateFiles = getTemplateFiles(); var trashFiles = getTrashFiles(); + //var anonFiles = getAnonFiles(); var toClean = []; fd.forEach(function (el, idx) { if (typeof(el) !== "object") { debug("An element in filesData was not an object.", el); toClean.push(el); - } else { - if (rootFiles.indexOf(el.href) === -1 - && unsortedFiles.indexOf(el.href) === -1 - && trashFiles.indexOf(el.href) === -1) { - debug("An element in filesData was not in ROOT, UNSORTED or TRASH.", el); - files[UNSORTED].push(el.href); - } + return; + } + if (el.owner + && rootFiles.indexOf(el.href) === -1 + && unsortedFiles.indexOf(el.href) === -1 + && templateFiles.indexOf(el.href) === -1 + && trashFiles.indexOf(el.href) === -1) { + debug("An element in filesData was not in ROOT, UNSORTED or TRASH.", el); + files[UNSORTED].push(el.href); + return; } + /*if (!el.owner && anonFiles.indexOf(el.href) === -1) { + files[ANON].push(el.href); + }*/// TODO }); toClean.forEach(function (el) { var idx = fd.indexOf(el); diff --git a/www/drive/file.css b/www/drive/file.css index 2fad2fd94..d6c1f2274 100644 --- a/www/drive/file.css +++ b/www/drive/file.css @@ -97,7 +97,7 @@ li { text-decoration: underline; } -#tree #trashTree, #tree #unsortedTree, #tree #templateTree, #tree #allfilesTree { +#tree .category2 { margin-top: 2em; } diff --git a/www/drive/main.js b/www/drive/main.js index 308beed83..d1d89ee35 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -26,7 +26,8 @@ define([ var APP = window.APP = { $bar: $iframe.find('#toolbar'), editable: false, - Cryptpad: Cryptpad + Cryptpad: Cryptpad, + loggedIn: Cryptpad.isLoggedIn() }; var stringify = APP.stringify = function (obj) { @@ -43,6 +44,11 @@ define([ var TEMPLATE_NAME = Messages.fm_templateName; var TRASH = "trash"; var TRASH_NAME = Messages.fm_trashName; + + // anon: Virtual path, not stored in the object but extracted from FILES_DATA + var ANON = "anon"; + var ANON_NAME = Messages.fm_anonName || 'Anon pads......'; + var LOCALSTORAGE_LAST = "cryptpad-file-lastOpened"; var LOCALSTORAGE_OPENED = "cryptpad-file-openedFolders"; var LOCALSTORAGE_VIEWMODE = "cryptpad-file-viewMode"; @@ -130,7 +136,8 @@ define([ else { $iframe.find('[draggable="false"]').attr('draggable', true); } }; - var init = function (files) { + var init = function (proxy) { + var files = proxy.drive; var isOwnDrive = function () { return Cryptpad.getUserHash() === APP.hash || localStorage.FS_hash === APP.hash; }; @@ -166,7 +173,7 @@ define([ // FILE MANAGER // _WORKGROUP_ and other people drive : display Documents as main page - var currentPath = module.currentPath = isOwnDrive() ? getLastOpenedFolder() : [ROOT]; + var currentPath = module.currentPath = APP.loggedIn ? isOwnDrive() ? getLastOpenedFolder() : [ROOT] : [ANON]; var lastSelectTime; var selectedElement; @@ -725,6 +732,7 @@ define([ else if (name === TRASH && path.length === 1) { name = TRASH_NAME; } else if (name === UNSORTED && path.length === 1) { name = UNSORTED_NAME; } else if (name === TEMPLATE && path.length === 1) { name = TEMPLATE_NAME; } + else if (name === ANON && path.length === 1) { name = ANON_NAME; } else if (name === FILES_DATA && path.length === 1) { name = FILES_DATA_NAME; } else if (filesOp.isPathInTrash(path)) { name = getTrashTitle(path); } var $title = $('