Fix an issue when deleting a key from the proxy

pull/1/head
yflory 8 years ago
parent 82f3d5f852
commit d95a3ac92e

@ -143,7 +143,7 @@ define([
}); });
}).on('ready', function () { }).on('ready', function () {
if (JSON.stringify(rt.proxy) === '{}') { if (!rt.proxy[Cryptpad.storageKey] || !Cryptpad.isArray(rt.proxy[Cryptpad.storageKey])) {
var oldStore = Cryptpad.getStore(true); var oldStore = Cryptpad.getStore(true);
oldStore.get(Cryptpad.storageKey, function (err, s) { oldStore.get(Cryptpad.storageKey, function (err, s) {
rt.proxy.filesData = s; rt.proxy.filesData = s;

@ -213,6 +213,7 @@ define([
for (var e in root) { for (var e in root) {
if (isFile(root[e])) { if (isFile(root[e])) {
if (compareFiles(href, root[e])) { if (compareFiles(href, root[e])) {
root[e] = undefined;
delete root[e]; delete root[e];
} }
} else { } else {
@ -256,6 +257,7 @@ define([
} else if (path[0] === UNSORTED) { } else if (path[0] === UNSORTED) {
parentEl.splice(key, 1); parentEl.splice(key, 1);
} else { } else {
parentEl[key] = undefined;
delete parentEl[key]; delete parentEl[key];
} }
checkDeletedFiles(); checkDeletedFiles();
@ -387,7 +389,6 @@ define([
log("A file with the same name already exist at the new location. Rename the file and try again."); log("A file with the same name already exist at the new location. Rename the file and try again.");
return; return;
} }
newParent[newName] = element; newParent[newName] = element;
if (!keepOld) { deleteFromObject(elementPath); } if (!keepOld) { deleteFromObject(elementPath); }
if(cb) { cb(); } if(cb) { cb(); }
@ -454,8 +455,9 @@ define([
if (index > -1) { if (index > -1) {
array.splice(index, 1); array.splice(index, 1);
} }
// Remove the array is empty to have a cleaner object in chainpad // Remove the array if empty to have a cleaner object in chainpad
if (array.length === 0) { if (array.length === 0) {
files[TRASH][name] = undefined;
delete files[TRASH][name]; delete files[TRASH][name];
} }
}; };
@ -512,6 +514,7 @@ define([
logError("Unable to locate the element to remove from trash: ", path); logError("Unable to locate the element to remove from trash: ", path);
return; return;
} }
parentEl[name] = undefined;
delete parentEl[name]; delete parentEl[name];
} }
checkDeletedFiles(); checkDeletedFiles();
@ -543,6 +546,7 @@ define([
return; return;
} }
parentEl[newName] = element; parentEl[newName] = element;
parentEl[oldName] = undefined;
delete parentEl[oldName]; delete parentEl[oldName];
cb(); cb();
}; };
@ -612,6 +616,7 @@ define([
for (var el in element) { for (var el in element) {
if (!isFile(element[el]) && !isFolder(element[el])) { if (!isFile(element[el]) && !isFolder(element[el])) {
debug("An element in ROOT was not a folder nor a file. ", element[el]); debug("An element in ROOT was not a folder nor a file. ", element[el]);
element[el] = undefined;
delete element[el]; delete element[el];
} else if (isFolder(element[el])) { } else if (isFolder(element[el])) {
fixRoot(element[el]); fixRoot(element[el]);
@ -630,6 +635,7 @@ define([
for (var el in tr) { for (var el in tr) {
if (!$.isArray(tr[el])) { if (!$.isArray(tr[el])) {
debug("An element in TRASH root is not an array. ", tr[el]); debug("An element in TRASH root is not an array. ", tr[el]);
tr[el] = undefined;
delete tr[el]; delete tr[el];
} else { } else {
toClean = []; toClean = [];

@ -4,6 +4,7 @@
<meta content="text/html; charset=utf-8" http-equiv="content-type"/> <meta content="text/html; charset=utf-8" http-equiv="content-type"/>
<link rel="stylesheet" href="/bower_components/components-font-awesome/css/font-awesome.min.css"> <link rel="stylesheet" href="/bower_components/components-font-awesome/css/font-awesome.min.css">
<script src="/bower_components/jquery/dist/jquery.min.js"></script> <script src="/bower_components/jquery/dist/jquery.min.js"></script>
<script src="/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.min.css"> <link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="file.css" /> <link rel="stylesheet" href="file.css" />
</head> </head>

@ -8,8 +8,6 @@ define([
'json.sortify', 'json.sortify',
'/common/cryptpad-common.js', '/common/cryptpad-common.js',
'/file/fileObject.js', '/file/fileObject.js',
'/bower_components/jquery/dist/jquery.min.js',
'/bower_components/bootstrap/dist/js/bootstrap.min.js',
'/customize/pad.js' '/customize/pad.js'
], function (Config, Listmap, Crypto, TextPatcher, Messages, JSONSortify, Cryptpad, FO) { ], function (Config, Listmap, Crypto, TextPatcher, Messages, JSONSortify, Cryptpad, FO) {
var module = window.MODULE = {}; var module = window.MODULE = {};
@ -1316,25 +1314,33 @@ define([
} }
}); });
files.on('change', [], function () { var onRefresh = {
refresh: function() {
if (onRefresh.to) {
window.clearTimeout(onRefresh.to);
}
onRefresh.to = window.setTimeout(refresh, 500);
}
};
files.on('change', [], function (o, n, p) {
var path = arguments[2]; var path = arguments[2];
if ((filesOp.isPathInUnsorted(currentPath) && filesOp.isPathInUnsorted(path)) || if ((filesOp.isPathInUnsorted(currentPath) && filesOp.isPathInUnsorted(path)) ||
(path.length >= currentPath.length && filesOp.isSubpath(path, currentPath)) || (path.length >= currentPath.length && filesOp.isSubpath(path, currentPath)) ||
(filesOp.isPathInTrash(currentPath) && filesOp.isPathInTrash(path))) { (filesOp.isPathInTrash(currentPath) && filesOp.isPathInTrash(path))) {
// Reload after 50ms to make sure all the change events have been received // Reload after a few ms to make sure all the change events have been received
window.setTimeout(refresh, 200); onRefresh.refresh();
} else if (path.length && path[0] === FILES_DATA) { } else if (path.length && path[0] === FILES_DATA) {
refreshFilesData(); refreshFilesData();
} }
module.resetTree(); module.resetTree();
return false; return false;
}).on('remove', [], function () { }).on('remove', [], function (o, p) {
var path = arguments[1]; var path = arguments[1];
if ((filesOp.isPathInUnsorted(currentPath) && filesOp.isPathInUnsorted(path)) || if ((filesOp.isPathInUnsorted(currentPath) && filesOp.isPathInUnsorted(path)) ||
(path.length >= currentPath.length && filesOp.isSubpath(path, currentPath)) || (path.length >= currentPath.length && filesOp.isSubpath(path, currentPath)) ||
(filesOp.isPathInTrash(currentPath) && filesOp.isPathInTrash(path))) { (filesOp.isPathInTrash(currentPath) && filesOp.isPathInTrash(path))) {
// Reload after 50ms to make sure all the change events have been received // Reload after a few to make sure all the change events have been received
window.setTimeout(refresh, 200); onRefresh.to = window.setTimeout(refresh, 500);
} }
module.resetTree(); module.resetTree();
return false; return false;
@ -1373,7 +1379,7 @@ define([
readOnly: false, readOnly: false,
validateKey: secret.keys.validateKey || undefined, validateKey: secret.keys.validateKey || undefined,
crypto: Crypto.createEncryptor(secret.keys), crypto: Crypto.createEncryptor(secret.keys),
//logging: true logging: false
}; };
var rt = window.rt = module.rt = Listmap.create(listmapConfig); var rt = window.rt = module.rt = Listmap.create(listmapConfig);

Loading…
Cancel
Save