From e656a67c16b4e2f4c63878fbe4bad25c45024e76 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 11:05:39 +0100 Subject: [PATCH 01/16] Fix channel cache --- www/common/outer/cache-store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/common/outer/cache-store.js b/www/common/outer/cache-store.js index 067d2dda7..73dbb1a3e 100644 --- a/www/common/outer/cache-store.js +++ b/www/common/outer/cache-store.js @@ -94,7 +94,7 @@ define([ S.storeCache = function (id, validateKey, val, cb) { cb = Util.once(Util.mkAsync(cb || function () {})); - onReady.reg(function (allowed) { + onReady.reg(function () { if (!allowed) { return void cb('NOCACHE'); } if (!Array.isArray(val) || !validateKey) { return void cb('EINVAL'); } checkCheckpoints(val); From e3102d2746cd6ade72334029e4703924c3be7cc6 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 11:52:24 +0100 Subject: [PATCH 02/16] Throttle channel cache --- www/common/outer/cache-store.js | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/www/common/outer/cache-store.js b/www/common/outer/cache-store.js index 73dbb1a3e..ad9f1e04f 100644 --- a/www/common/outer/cache-store.js +++ b/www/common/outer/cache-store.js @@ -91,20 +91,29 @@ define([ array.splice(0, firstCpIdx); }; - S.storeCache = function (id, validateKey, val, cb) { - cb = Util.once(Util.mkAsync(cb || function () {})); + var t = {}; + S.storeCache = function (id, validateKey, val, onError) { + onError = Util.once(Util.mkAsync(onError || function () {})); onReady.reg(function () { - if (!allowed) { return void cb('NOCACHE'); } - if (!Array.isArray(val) || !validateKey) { return void cb('EINVAL'); } - checkCheckpoints(val); - cache.setItem(id, { - k: validateKey, - c: val, - t: (+new Date()) // 't' represent the "lastAccess" of this cache (get or set) - }, function (err) { - cb(err); - }); + + // Make a throttle or use the existing one to avoid calling + // storeCache with the same array multiple times + t[id] = t[id] || Util.throttle(function (validateKey, val, onError) { + if (!allowed) { return void onError('NOCACHE'); } + if (!Array.isArray(val) || !validateKey) { return void onError('EINVAL'); } + checkCheckpoints(val); + cache.setItem(id, { + k: validateKey, + c: val, + t: (+new Date()) // 't' represent the "lastAccess" of this cache (get or set) + }, function (err) { + if (err) { onError(err); } + }); + + }, 50); + t[id](validateKey, val, onError); + }); }; From ab4739005be4b5a17e9316b7aecb7f3250361bd8 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 11:57:46 +0100 Subject: [PATCH 03/16] Fix X icon in the share modal --- www/common/inner/share.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/common/inner/share.js b/www/common/inner/share.js index f3ca53f75..2be698d74 100644 --- a/www/common/inner/share.js +++ b/www/common/inner/share.js @@ -345,7 +345,7 @@ define([ localStore.get('hide-alert-shareLinkWarning', function (val) { if (val === '1') { return; } - $(shareLinkWarning).show(); + $(shareLinkWarning).css('display', 'flex'); $(dismissButton).on('click', function () { localStore.put('hide-alert-shareLinkWarning', '1'); From b3f91dd9a28240d61ee7c209a133c064a5c58fb4 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 12:02:48 +0100 Subject: [PATCH 04/16] Fix button margin in admin panel --- www/admin/app-admin.less | 3 +++ 1 file changed, 3 insertions(+) diff --git a/www/admin/app-admin.less b/www/admin/app-admin.less index 651e9dddd..8fff2e528 100644 --- a/www/admin/app-admin.less +++ b/www/admin/app-admin.less @@ -31,6 +31,9 @@ margin-top: 5px; } } + .cp-admin-setlimit-form + button { + margin-top: 5px !important; + } .cp-admin-getlimits { code { cursor: pointer; From 51ebdf4ed2433822c55f82fab9b1f4f044e15b25 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 12:06:18 +0100 Subject: [PATCH 05/16] Clear throttled functions in cache --- www/common/outer/async-store.js | 3 +++ www/common/outer/cache-store.js | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index afb799990..da7abf9d0 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -2277,6 +2277,9 @@ define([ try { store.onlyoffice.leavePad(chanId); } catch (e) { console.error(e); } + try { + Cache.leaveChannel(chanId); + } catch (e) { console.error(e); } if (!Store.channels[chanId]) { return; } diff --git a/www/common/outer/cache-store.js b/www/common/outer/cache-store.js index ad9f1e04f..4b21e22fe 100644 --- a/www/common/outer/cache-store.js +++ b/www/common/outer/cache-store.js @@ -117,6 +117,13 @@ define([ }); }; + S.leaveChannel = function (id) { + if (t[id] && typeof(t[id].clear) === "function") { + t[id].clear(); + } + delete t[id]; + }; + S.clearChannel = function (id, cb) { cb = Util.once(Util.mkAsync(cb || function () {})); From 453b207bcc02f72bc7cf3dba8ee38ceebe11df7f Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 12:09:19 +0100 Subject: [PATCH 06/16] Remove the throttled function from memory only --- www/common/outer/cache-store.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/www/common/outer/cache-store.js b/www/common/outer/cache-store.js index 4b21e22fe..7a0a50209 100644 --- a/www/common/outer/cache-store.js +++ b/www/common/outer/cache-store.js @@ -118,9 +118,6 @@ define([ }; S.leaveChannel = function (id) { - if (t[id] && typeof(t[id].clear) === "function") { - t[id].clear(); - } delete t[id]; }; From dfc2d6ce0ddfedd4af3de0f441e59dec365bd8ed Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 13:31:39 +0100 Subject: [PATCH 07/16] Remove deleted pad from cache --- www/common/outer/async-store.js | 1 + 1 file changed, 1 insertion(+) diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index da7abf9d0..90318dba5 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -331,6 +331,7 @@ define([ if (!s.rpc) { return void cb({error: 'RPC_NOT_READY'}); } s.rpc.removeOwnedChannel(channel, function (err) { + if (!err) { Cache.clearChannel(channel); } cb({error:err}); }); }; From a691b73f80a691f9674a17c22094a6d30aea0b18 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 14 Dec 2020 18:14:55 +0530 Subject: [PATCH 08/16] align the 'self-destruct' button to the right on the loading screen --- customize.dist/loading.js | 4 ++++ www/common/common-ui-elements.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/customize.dist/loading.js b/customize.dist/loading.js index 6e4781aaf..091ed9ad8 100644 --- a/customize.dist/loading.js +++ b/customize.dist/loading.js @@ -254,6 +254,10 @@ button:not(.btn).primary:hover{ background-color: rgb(52, 118, 162); } +nav { + text-align: right; +} + */}).toString().slice(14, -3); var urlArgs = window.location.href.replace(/^.*\?([^\?]*)$/, function (all, x) { return x; }); var elem = document.createElement('div'); diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 81b202ee0..8fcb9b194 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -2552,7 +2552,7 @@ define([ var block = h('div#cp-loading-burn-after-reading', [ info, - button + h('nav', button), ]); UI.errorLoadingScreen(block); }; From 2d6bc11f9c8ff5290aa7014fcc49c53c0ffa58a8 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 13:51:22 +0100 Subject: [PATCH 09/16] Remove console noise --- customize.dist/loading.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/customize.dist/loading.js b/customize.dist/loading.js index 6e4781aaf..8efca25fd 100644 --- a/customize.dist/loading.js +++ b/customize.dist/loading.js @@ -318,8 +318,8 @@ button:not(.btn).primary:hover{ // Make sure progress doesn't go backward var c = types.indexOf(data.type); - if (c < current) { return console.error(data); } - if (c === current && progress > data.progress) { return console.error(data); } + if (c < current) { return console.debug(data); } + if (c === current && progress > data.progress) { return console.debug(data); } progress = data.progress; try { From eb5c93965a05f227fd9b32d2da882fc8d6b2e025 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 13:51:36 +0100 Subject: [PATCH 10/16] Clear cache when channel or blob is deleted --- www/common/outer/async-store.js | 2 ++ www/common/sframe-common-outer.js | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 90318dba5..58fd28e00 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -464,6 +464,7 @@ define([ store.anon_rpc.send("GET_FILE_SIZE", channelId, function (e, response) { if (e) { return void cb({error: e}); } if (response && response.length && typeof(response[0]) === 'number') { + if (response[0] === 0) { Cache.clearChannel(channelId); } return void cb({size: response[0]}); } else { cb({error: 'INVALID_RESPONSE'}); @@ -477,6 +478,7 @@ define([ store.anon_rpc.send("IS_NEW_CHANNEL", channelId, function (e, response) { if (e) { return void cb({error: e}); } if (response && response.length && typeof(response[0]) === 'boolean') { + if (response[0]) { Cache.clearChannel(channelId); } return void cb({ isNew: response[0] }); diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index 44cbb3e3c..b7610f684 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -480,6 +480,7 @@ define([ // We've received a link without /p/ and it doesn't work without a password: abort return void todo(); } + // Wrong password or deleted file? askPassword(true, passwordCfg); })); @@ -534,6 +535,12 @@ define([ var edPublic, curvePublic, notifications, isTemplate; var settings = {}; var isSafe = ['debug', 'profile', 'drive', 'teams'].indexOf(currentPad.app) !== -1; + + var isDeleted = isNewFile && currentPad.hash.length > 0; + if (isDeleted) { + Utils.Cache.clearChannel(secret.channel); + } + var updateMeta = function () { //console.log('EV_METADATA_UPDATE'); var metaObj; @@ -577,7 +584,7 @@ define([ upgradeURL: Cryptpad.upgradeURL }, isNewFile: isNewFile, - isDeleted: isNewFile && currentPad.hash.length > 0, + isDeleted: isDeleted, password: password, channel: secret.channel, enableSF: localStorage.CryptPad_SF === "1", // TODO to remove when enabled by default From 74340c66d62f9e12739e6111f1c6646beb08a847 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 14 Dec 2020 18:41:07 +0530 Subject: [PATCH 11/16] use inline styles to prevent leaking css --- customize.dist/loading.js | 4 ---- www/common/common-ui-elements.js | 4 +++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/customize.dist/loading.js b/customize.dist/loading.js index 091ed9ad8..6e4781aaf 100644 --- a/customize.dist/loading.js +++ b/customize.dist/loading.js @@ -254,10 +254,6 @@ button:not(.btn).primary:hover{ background-color: rgb(52, 118, 162); } -nav { - text-align: right; -} - */}).toString().slice(14, -3); var urlArgs = window.location.href.replace(/^.*\?([^\?]*)$/, function (all, x) { return x; }); var elem = document.createElement('div'); diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index 8fcb9b194..93b9e3648 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -2552,7 +2552,9 @@ define([ var block = h('div#cp-loading-burn-after-reading', [ info, - h('nav', button), + h('nav', { + style: 'text-align: right' + }, button), ]); UI.errorLoadingScreen(block); }; From db80b7541a0e24eeaaba30f183835c4e6cf4db91 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 14:53:37 +0100 Subject: [PATCH 12/16] Fix mediatag size in settings --- www/settings/inner.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/www/settings/inner.js b/www/settings/inner.js index b4668efff..b4290becb 100644 --- a/www/settings/inner.js +++ b/www/settings/inner.js @@ -593,8 +593,8 @@ define([ var todo = function () { var val = parseInt($input.val()); + if (typeof(val) !== 'number' || isNaN(val)) { return UI.warn(Messages.error); } if (val === oldVal) { return; } - if (typeof(val) !== 'number') { return UI.warn(Messages.error); } spinner.spin(); common.setAttribute(['general', 'mediatag-size'], val, function (err) { if (err) { @@ -602,6 +602,7 @@ define([ console.error(err); return UI.warn(Messages.error); } + oldVal = val; spinner.done(); UI.log(Messages.saved); }); @@ -616,7 +617,7 @@ define([ common.getAttribute(['general', 'mediatag-size'], function(e, val) { if (e) { return void console.error(e); } - if (typeof(val) !== 'number') { + if (typeof(val) !== 'number' || isNaN(val)) { oldVal = 5; $input.val(5); } else { From efcb30234afbbdb47286419fbd2d4dadc96c8787 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 15:26:24 +0100 Subject: [PATCH 13/16] Add max upload size in the upload errors --- www/common/sframe-common-file.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index 7b8601f13..6a0367b69 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -1,5 +1,6 @@ define([ 'jquery', + '/api/config', '/file/file-crypto.js', '/common/make-backup.js', '/common/common-thumbnail.js', @@ -12,7 +13,7 @@ define([ '/bower_components/file-saver/FileSaver.min.js', '/bower_components/tweetnacl/nacl-fast.min.js', -], function ($, FileCrypto, MakeBackup, Thumb, UI, UIElements, Util, Hash, h, Messages) { +], function ($, ApiConfig, FileCrypto, MakeBackup, Thumb, UI, UIElements, Util, Hash, h, Messages) { var Nacl = window.nacl; var module = {}; @@ -166,8 +167,12 @@ define([ if (config.onError) { config.onError(e); } if (e === 'TOO_LARGE') { - $pv.text(Messages.upload_tooLargeBrief); - return void UI.alert(Messages.upload_tooLarge); + var privateData = common.getMetadataMgr().getPrivateData(); + var l = privateData.plan ? ApiConfig.premiumUploadSize : false; + l = l || ApiConfig.maxUploadSize || '?'; + var maxSizeStr = Util.bytesToMegabytes(l); + $pv.text(Messages.error); + return void UI.alert(Messages._getKey('upload_tooLargeBrief', [maxSizeStr])); } if (e === 'NOT_ENOUGH_SPACE') { $pv.text(Messages.upload_notEnoughSpaceBrief); From 9cb683c73e6926faa74bc02a7d333ec52c0e4a56 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 14 Dec 2020 20:16:19 +0530 Subject: [PATCH 14/16] fix whiteboard image embed too large warning --- www/whiteboard/inner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/whiteboard/inner.js b/www/whiteboard/inner.js index 30c43aef1..e0492309f 100644 --- a/www/whiteboard/inner.js +++ b/www/whiteboard/inner.js @@ -332,7 +332,7 @@ define([ }); }; var MAX_IMAGE_SIZE = 1 * 1024 * 1024; // 1 MB - var maxSizeStr = Messages._getKey('formattedMB', [Util.bytesToMegabytes(MAX_IMAGE_SIZE)]); + var maxSizeStr = Util.bytesToMegabytes(MAX_IMAGE_SIZE); var addImageToCanvas = function (img) { if (img.src && img.src.length > MAX_IMAGE_SIZE) { UI.warn(Messages._getKey('upload_tooLargeBrief', [maxSizeStr])); From 23e6dac8d4d15b15f00fcd227443c780a874bf8c Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 16:01:01 +0100 Subject: [PATCH 15/16] Update teams slots default values --- www/common/application_config_internal.js | 4 ++-- www/common/common-constants.js | 4 ++-- www/teams/inner.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/www/common/application_config_internal.js b/www/common/application_config_internal.js index 3185f2e29..1e848d289 100644 --- a/www/common/application_config_internal.js +++ b/www/common/application_config_internal.js @@ -169,7 +169,7 @@ define(function() { // make them have a very slow loading time. To avoid impacting the user experience // significantly, we're limiting the number of teams per user to 3 by default. // You can change this value here. - //config.maxTeamsSlots = 3; + //config.maxTeamsSlots = 5; // Each team is considered as a registered user by the server. Users and teams are indistinguishable // in the database so teams will offer the same storage limits as users by default. @@ -177,7 +177,7 @@ define(function() { // We're limiting the number of teams each user is able to own to 1 in order to make sure // users don't use "fake" teams (1 member) just to increase their storage limit. // You can change the value here. - // config.maxOwnedTeams = 1; + // config.maxOwnedTeams = 5; return config; }); diff --git a/www/common/common-constants.js b/www/common/common-constants.js index 17db2302c..fdae2b5de 100644 --- a/www/common/common-constants.js +++ b/www/common/common-constants.js @@ -12,8 +12,8 @@ define(['/customize/application_config.js'], function (AppConfig) { tokenKey: 'loginToken', displayPadCreationScreen: 'displayPadCreationScreen', deprecatedKey: 'deprecated', - MAX_TEAMS_SLOTS: AppConfig.maxTeamsSlots || 3, - MAX_TEAMS_OWNED: AppConfig.maxOwnedTeams || 1, + MAX_TEAMS_SLOTS: AppConfig.maxTeamsSlots || 5, + MAX_TEAMS_OWNED: AppConfig.maxOwnedTeams || 5, // Apps criticalApps: ['profile', 'settings', 'debug', 'admin', 'support', 'notifications'] }; diff --git a/www/teams/inner.js b/www/teams/inner.js index 7af3d7afc..2c37eabf0 100644 --- a/www/teams/inner.js +++ b/www/teams/inner.js @@ -476,7 +476,7 @@ define([ var getWarningBox = function () { return h('div.alert.alert-warning', { role:'alert' - }, isOwner ? Messages.team_maxOwner : Messages._getKey('team_maxTeams', [MAX_TEAMS_SLOTS])); + }, Messages._getKey('team_maxTeams', [MAX_TEAMS_SLOTS])); }; if (Object.keys(privateData.teams || {}).length >= Constants.MAX_TEAMS_SLOTS || isOwner) { From b8780d468b9c72aa72802d913b4baea0c7e5d439 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Dec 2020 16:34:38 +0100 Subject: [PATCH 16/16] Fix ReferenceError with Notification --- www/common/sframe-common-outer.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index b7610f684..ca760efb8 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -97,6 +97,7 @@ define([ '/common/common-hash.js', '/common/common-util.js', '/common/common-realtime.js', + '/common/notify.js', '/common/common-constants.js', '/common/common-feedback.js', '/common/outer/local-store.js', @@ -105,7 +106,7 @@ define([ '/common/test.js', '/common/userObject.js', ], waitFor(function (_CpNfOuter, _Cryptpad, _Crypto, _Cryptget, _SFrameChannel, - _SecureIframe, _Messaging, _Notifier, _Hash, _Util, _Realtime, + _SecureIframe, _Messaging, _Notifier, _Hash, _Util, _Realtime, _Notify, _Constants, _Feedback, _LocalStore, _Cache, _AppConfig, _Test, _UserObject) { CpNfOuter = _CpNfOuter; Cryptpad = _Cryptpad; @@ -123,6 +124,7 @@ define([ Utils.LocalStore = _LocalStore; Utils.Cache = _Cache; Utils.UserObject = _UserObject; + Utils.Notify = _Notify; Utils.currentPad = currentPad; AppConfig = _AppConfig; Test = _Test; @@ -564,6 +566,7 @@ define([ defaultTitle: defaultTitle, type: cfg.type || parsed.type }; + var notifs = Utils.Notify.isSupported() && Utils.Notify.hasPermission(); var additionalPriv = { app: parsed.type, loggedIn: Utils.LocalStore.isLoggedIn(), @@ -578,7 +581,7 @@ define([ isPresent: parsed.hashData && parsed.hashData.present, isEmbed: parsed.hashData && parsed.hashData.embed, isHistoryVersion: parsed.hashData && parsed.hashData.versionHash, - notifications: Notification && Notification.permission === "granted", + notifications: notifs, accounts: { donateURL: Cryptpad.donateURL, upgradeURL: Cryptpad.upgradeURL @@ -1605,6 +1608,7 @@ define([ }); sframeChan.on('Q_ASK_NOTIFICATION', function (data, cb) { + if (!Utils.Notify.isSupported()) { return void cb(false); } Notification.requestPermission(function (s) { cb(s === "granted"); });