Anonymous pads fo anonymous users
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user