From 6516b1ec487241b653749d4ae3ea709b4d24c494 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 6 Apr 2022 16:36:54 +0530 Subject: [PATCH] use historical shared folder data when viewing drive history --- www/common/drive-ui.js | 30 ++++++++++++++++++++++++++---- www/common/inner/share.js | 2 +- www/common/proxy-manager.js | 12 ++++++++++-- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/www/common/drive-ui.js b/www/common/drive-ui.js index 86ea3889d..053f2809d 100644 --- a/www/common/drive-ui.js +++ b/www/common/drive-ui.js @@ -4525,6 +4525,14 @@ define([ var type = $contextMenu.attr('data-menu-type'); var $this = $(this); + var prefix = /cp\-app\-drive\-context\-/; + var command = Util.slice(this.classList) + .map(c => { + if (!prefix.test(c)) { return; } + return c.replace(prefix, ''); + }).filter(Boolean); + console.log(command); + var el, data; if (paths.length === 0) { log(Messages.fm_forbidden); @@ -4784,9 +4792,13 @@ define([ common: common }; if (padType === 'file') { - return void Share.getFileShareModal(common, padData); + return void Share.getFileShareModal(common, padData, function (err) { + if (err) { UI.warn(Messages.error); } + }); } - Share.getShareModal(common, padData); + Share.getShareModal(common, padData, function (err) { + if (err) { UI.warn(Messages.error); } + }); } } else if ($this.hasClass('cp-app-drive-context-savelocal')) { @@ -4875,7 +4887,10 @@ define([ el = manager.find(paths[0].path.slice(1), APP.newSharedFolder); } APP.getProperties(el, function (e) { - if (e) { return void logError(e); } + if (e) { + UI.warn(Messages.error); + return void logError(e, el); + } }); } else if ($this.hasClass("cp-app-drive-context-access")) { @@ -4886,7 +4901,10 @@ define([ el = manager.find(paths[0].path.slice(1), APP.newSharedFolder); } APP.getAccess(el, function (e) { - if (e) { return void logError(e); } + if (e) { + UI.warn(Messages.error); + return void logError(e); + } }); } else if ($this.hasClass("cp-app-drive-context-hashtag")) { @@ -5130,14 +5148,17 @@ define([ if (!obj || typeof(obj) !== "object" || Object.keys(obj).length === 0) { return; } + manager.setHistoryMode(true); copyObjectValue(folders[history.sfId], obj); refresh(); return; } + history.sfId = false; var ok = manager.isValidDrive(obj.drive); if (!ok) { return; } + manager.setHistoryMode(true); var restricted = files.restrictedFolders; copyObjectValue(files, obj.drive); @@ -5147,6 +5168,7 @@ define([ refresh(); }; history.onLeaveHistory = function () { + manager.setHistoryMode(false); copyObjectValue(files, proxy.drive); refresh(); }; diff --git a/www/common/inner/share.js b/www/common/inner/share.js index d9cae4c3b..13668a00c 100644 --- a/www/common/inner/share.js +++ b/www/common/inner/share.js @@ -730,7 +730,7 @@ define([ opts.access = true; // Allow the use of the modal even if the pad is not stored var hashes = opts.hashes; - if (!hashes || (!hashes.editHash && !hashes.viewHash && !opts.static)) { return; } + if (!hashes || (!hashes.editHash && !hashes.viewHash && !opts.static)) { return cb("NO_HASHES"); } var teams = getEditableTeams(common, opts); opts.teams = teams; diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index 5cf44b467..926335eb9 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -236,8 +236,10 @@ define([ }; var getSharedFolderData = function (Env, id) { - if (!Env.folders[id]) { return {}; } - var proxy = Env.folders[id].proxy; + var inHistory; + if (Env.isHistoryMode && !Env.folders[id]) { inHistory = true; } + else if (!Env.folders[id]) { return {}; } + var proxy = inHistory? {}: Env.folders[id].proxy; // Clean deprecated values if (Object.keys(proxy.metadata || {}).length > 1) { @@ -522,6 +524,7 @@ define([ href: '/drive/#' + hashes.editHash, roHref: '/drive/#' + hashes.viewHash, channel: secret.channel, + lastTitle: data.name, ctime: +new Date(), }; if (data.password) { folderData.password = data.password; } @@ -1562,6 +1565,10 @@ define([ return Env.user.userObject.getOwnedPads(Env.edPublic); }; + var setHistoryMode = function (Env, flag) { + Env.isHistoryMode = Boolean(flag); + }; + var getFolderData = function (Env, path) { var resolved = _resolvePath(Env, path); if (!resolved || !resolved.userObject) { return {}; } @@ -1657,6 +1664,7 @@ define([ // Manager addProxy: callWithEnv(addProxy), removeProxy: callWithEnv(removeProxy), + setHistoryMode: callWithEnv(setHistoryMode), // Drive RPC commands rename: callWithEnv(renameInner), move: callWithEnv(moveInner),