From 21658e9de1d2ffa9abb41c033dd2280afe02b0bb Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 12 Aug 2019 15:52:48 +0200 Subject: [PATCH 1/2] Fix restoring an older version of the drive --- www/common/cryptpad-common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index fef46951c..e761f0ad5 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -138,7 +138,7 @@ define([ } postMessage("SET", { key:['drive'], - value: data + value: data.drive }, function (obj) { cb(obj); }, { From bbd59c6a2b7a0bf002bc023b335b1e9c9f38f7d2 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 12 Aug 2019 16:14:44 +0200 Subject: [PATCH 2/2] Don't freeze the UI with old (invalid) states of the drive history --- www/common/proxy-manager.js | 4 ++++ www/common/userObject.js | 14 ++++++++++++++ www/drive/inner.js | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index 1257f3ad4..7f20ae5b6 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -1036,6 +1036,9 @@ define([ var isInSharedFolder = _isInSharedFolder; /* Generic: doesn't need access to a proxy */ + var isValidDrive = function (Env, obj) { + return Env.user.userObject.isValidDrive(obj); + }; var isFile = function (Env, el, allowStr) { return Env.user.userObject.isFile(el, allowStr); }; @@ -1131,6 +1134,7 @@ define([ getUserObjectPath: callWithEnv(getUserObjectPath), isDuplicateOwned: callWithEnv(isDuplicateOwned), // Generic + isValidDrive: callWithEnv(isValidDrive), isFile: callWithEnv(isFile), isFolder: callWithEnv(isFolder), isSharedFolder: callWithEnv(isSharedFolder), diff --git a/www/common/userObject.js b/www/common/userObject.js index 39b55484a..fe99f9935 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -72,8 +72,22 @@ define([ a[TRASH] = {}; a[FILES_DATA] = {}; a[TEMPLATE] = []; + a[SHARED_FOLDERS] = {}; return a; }; + + var type = function (dat) { + return dat === null? 'null': Array.isArray(dat)?'array': typeof(dat); + }; + exp.isValidDrive = function (obj) { + var base = exp.getStructure(); + return typeof (obj) === "object" && + Object.keys(base).every(function (key) { + console.log(key, obj[key], type(obj[key])); + return obj[key] && type(base[key]) === type(obj[key]); + }); + }; + var getHrefArray = function () { return [TEMPLATE]; }; diff --git a/www/drive/inner.js b/www/drive/inner.js index f69c36060..606de2866 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -3900,6 +3900,10 @@ define([ return; } history.sfId = false; + + var ok = manager.isValidDrive(obj.drive); + if (!ok) { return; } + copyObjectValue(files, obj.drive); appStatus.isReady = true; refresh();