From a190af079d1b5e5fce7855e865f540e5e0419707 Mon Sep 17 00:00:00 2001 From: Alexander <7adietri@users.noreply.github.com> Date: Sat, 21 Mar 2020 14:43:25 +0100 Subject: [PATCH 01/12] Add shutdown() to non-disk logger The script `evict-inactive.js` calls `Log.shutdown()` at the end, which currently fails if logging to disk has been disabled via `logPath`. --- lib/log.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/log.js b/lib/log.js index 756da8734..695f15b04 100644 --- a/lib/log.js +++ b/lib/log.js @@ -96,7 +96,9 @@ Logger.create = function (config, cb) { if (!config.logPath) { console.log("No logPath configured. Logging to file disabled"); - return void cb(Object.freeze(createMethods(ctx))); + var logger = createMethods(ctx); + logger.shutdown = noop; + return void cb(Object.freeze(logger)); } Store.create({ From f3e6c6c36d2083f4b10471c4fe9594140636cbb1 Mon Sep 17 00:00:00 2001 From: Weblate Date: Mon, 23 Mar 2020 11:53:37 +0100 Subject: [PATCH 02/12] Translated using Weblate (Italian) Currently translated at 69.7% (865 of 1241 strings) Translation: CryptPad/App Translate-URL: http://weblate.cryptpad.fr/projects/cryptpad/app/it/ --- www/common/translations/messages.it.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/www/common/translations/messages.it.json b/www/common/translations/messages.it.json index d022c91b5..7e7d8a01f 100644 --- a/www/common/translations/messages.it.json +++ b/www/common/translations/messages.it.json @@ -582,7 +582,8 @@ "a": "Pad è un termine popolare per Etherpad, un editor collaborativo in tempo reale.\nSi riferisce ad un documento che puoi modificare nel tuo browser, generalmente con le modifiche di altri utenti visibili in modo quasi istantaneo." }, "expiring": { - "q": "Cos'è un pad effimero?" + "q": "Cos'è un pad effimero?", + "a": "Un expiring pad è un pad creato con una scadenza, raggiunta il pad verrà automaticamente cancellato dal server. Gli expiring pad possono essere configurati per durare da un minimo di un'ora ad un massimo di 100 mesi. Il pad e tutta la sua cronologia diventeranno permanentemente non disponibili anche se vengono modificati nel momento in cui scadono.

Se un pad è impostato con una scadenza, puoi controllare il suo tempo di durata visualizzando le sue proprietà , sia facendo clic con il tasto destro del mouse sul pad in CryptDrive, sia usando la proprietà -menu dalla barra degli strumenti di un'applicazione." }, "owned": { "a": "Un pad di proprietà è un pad creato da un esplicito proprietario, identificato dal server dalla sua chiave di crittografia pubblica. Il proprietario di un pad può scegliere di cancellare i suoi pad dal server, rendendoli invalidi per gli altri collaboratori nel futuro, sia che essi li avessero oppure no nei loro Cryptdrive.", From ee8d5c9c3698bf5c0adde2a1344cd82f5a25d498 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 23 Mar 2020 16:13:48 -0400 Subject: [PATCH 03/12] fix the premiumUploadSize validation to check the correct attribute --- lib/load-config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/load-config.js b/lib/load-config.js index 4d6fa894f..49dbbf58a 100644 --- a/lib/load-config.js +++ b/lib/load-config.js @@ -38,7 +38,7 @@ if (!isPositiveNumber(config.defaultStorageLimit)) { // premiumUploadSize is worthless if it isn't a valid positive number // or if it's less than the default upload size -if (!isPositiveNumber(config.premiumUploadSize) || config.premiumUploadSize < config.defaultStorageLimit) { +if (!isPositiveNumber(config.premiumUploadSize) || config.premiumUploadSize < config.maxUploadSize) { delete config.premiumUploadSize; } From cc335a54b1c6dc6dff3ff36ebe179ca701c10dae Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 23 Mar 2020 18:56:04 -0400 Subject: [PATCH 04/12] update chainpad-server to latest version --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index e9abb0519..99f65cf27 100644 --- a/package-lock.json +++ b/package-lock.json @@ -190,9 +190,9 @@ } }, "chainpad-server": { - "version": "4.0.7", - "resolved": "https://registry.npmjs.org/chainpad-server/-/chainpad-server-4.0.7.tgz", - "integrity": "sha512-79BTtbFI/nP3HCzPcth8VyeGPYZXGxQRJ8Vm5gE1/hIXWP5ktqBVyabiTiJwsA0tXCAznSa+jnY1DmOLcvCKvA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/chainpad-server/-/chainpad-server-4.0.8.tgz", + "integrity": "sha512-QlmomAMQN4msdYnRqGEjL12FAeOPIJ5yoxIzROohWt/31SwF1UlyV+zFp1M1dhtV8PoS7JXvLyBBLCEEVN73Cg==", "requires": { "nthen": "0.1.8", "pull-stream": "^3.6.9", diff --git a/package.json b/package.json index f042d7981..a12997e39 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "chainpad-crypto": "^0.2.2", - "chainpad-server": "^4.0.7", + "chainpad-server": "^4.0.8", "express": "~4.16.0", "fs-extra": "^7.0.0", "get-folder-size": "^2.0.1", From 2ef0af29e548ca9c08fca008b32cd6bd15f190b9 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 23 Mar 2020 22:03:59 -0400 Subject: [PATCH 05/12] guard against index worker rpc responses for a txid with no supplied callback --- lib/hk-util.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/hk-util.js b/lib/hk-util.js index 97e5c3014..bfc9883c1 100644 --- a/lib/hk-util.js +++ b/lib/hk-util.js @@ -835,7 +835,14 @@ HK.initializeIndexWorkers = function (Env, config, _cb) { worker.on('message', function (res) { if (!res || !res.txid) { return; } //console.log(res); - response.handle(res.txid, [res.error, res.value]); + try { + response.handle(res.txid, [res.error, res.value]); + } catch (err) { + Env.Log.error("INDEX_WORKER", { + error: err, + response: res, + }); + } }); worker.on('exit', function () { var idx = workers.indexOf(worker); From 24e474e6884e968b9dc76c8f033f37faf899f705 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 24 Mar 2020 15:25:58 +0100 Subject: [PATCH 06/12] Big canvas --- www/whiteboard/app-whiteboard.less | 4 ++- www/whiteboard/inner.js | 42 +++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/www/whiteboard/app-whiteboard.less b/www/whiteboard/app-whiteboard.less index 0ac575df6..b715e188c 100644 --- a/www/whiteboard/app-whiteboard.less +++ b/www/whiteboard/app-whiteboard.less @@ -35,7 +35,6 @@ #cp-app-whiteboard-container { flex: 1; display: flex; - flex-flow: column; overflow: auto; } @@ -43,14 +42,17 @@ #cp-app-whiteboard-canvas-area { flex: 1; display: flex; + min-height: 0; } // created by fabricjs. styled so defaults don't break anything .cp-app-whiteboard-canvas-container { + width: 100%; margin: auto; background: white; flex: 1; min-height: 0; & > canvas { + width: 100%; border: 1px solid black; } } diff --git a/www/whiteboard/inner.js b/www/whiteboard/inner.js index 77057f505..e45cc35f0 100644 --- a/www/whiteboard/inner.js +++ b/www/whiteboard/inner.js @@ -137,7 +137,7 @@ define([ canvas.discardActiveGroup(); } canvas.renderAll(); - framework.localChange(); + APP.onLocal(); }; $deleteButton.click(deleteSelection); $(window).on('keyup', function (e) { @@ -220,7 +220,7 @@ define([ var metadata = JSON.parse(JSON.stringify(metadataMgr.getMetadata())); metadata.palette = newPalette; metadataMgr.updateMetadata(metadata); - framework.localChange(); + APP.onLocal(); }; var makeColorButton = function ($container) { @@ -284,6 +284,35 @@ define([ }); var $canvas = $('canvas'); var $canvasContainer = $('canvas').parents('.cp-app-whiteboard-canvas-container'); + + // Max for old macs: 2048×1464 + // Max for IE: 8192x8192 + var MAX = 8192; + var onResize = APP.onResize = function () { + $canvasContainer.css('width', ''); + $canvasContainer.css('height', ''); + var w = $canvasContainer.width() - 20; + var h = $canvasContainer.height(); + canvas.forEachObject(function (obj) { + var c = obj.getCoords(); + Object.keys(c).forEach(function (k) { + if (c[k].x > w) { w = c[k].x + 1; } + if (c[k].y > h) { h = c[k].y + 1; } + }); + }); + w = Math.min(w, MAX); + h = Math.min(h, MAX); + canvas.setWidth(w); + canvas.setHeight(h); + canvas.calcOffset(); + }; + $(window).on('resize', onResize); + + var onLocal = APP.onLocal = function () { + framework.localChange(); + APP.onResize(); + }; + var $controls = $('#cp-app-whiteboard-controls'); var metadataMgr = framework._.cpNfInner.metadataMgr; @@ -333,7 +362,7 @@ define([ } var cImg = new Fabric.Image(img, { left:0, top:0, angle:0, }); APP.canvas.add(cImg); - framework.localChange(); + onLocal(); }; // Embed image @@ -403,7 +432,7 @@ define([ $('#cp-app-whiteboard-clear').on('click', function () { canvas.clear(); - framework.localChange(); + onLocal(); }); // --------------------------------------------- @@ -432,6 +461,7 @@ define([ var content = newContent.content; canvas.loadFromJSON(content, waitFor(function () { canvas.renderAll(); + onResize(); })); }); @@ -461,7 +491,7 @@ define([ window.setTimeout(mkThumbnail, Thumb.UPDATE_FIRST); }); - canvas.on('mouse:up', framework.localChange); + canvas.on('mouse:up', onLocal); framework.start(); }; @@ -471,8 +501,6 @@ define([ h('div#cp-app-whiteboard-canvas-area', h('div#cp-app-whiteboard-container', h('canvas#cp-app-whiteboard-canvas', { - width: 600, - height: 600 }) ) ), From ae1b59b2c14a86ab9a777cac68e0b4e6caceaff3 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 24 Mar 2020 15:32:56 +0100 Subject: [PATCH 07/12] Fix canvas initial size --- www/whiteboard/inner.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/www/whiteboard/inner.js b/www/whiteboard/inner.js index e45cc35f0..2c3125903 100644 --- a/www/whiteboard/inner.js +++ b/www/whiteboard/inner.js @@ -284,15 +284,14 @@ define([ }); var $canvas = $('canvas'); var $canvasContainer = $('canvas').parents('.cp-app-whiteboard-canvas-container'); + var $container = $('#cp-app-whiteboard-container'); // Max for old macs: 2048×1464 // Max for IE: 8192x8192 var MAX = 8192; var onResize = APP.onResize = function () { - $canvasContainer.css('width', ''); - $canvasContainer.css('height', ''); - var w = $canvasContainer.width() - 20; - var h = $canvasContainer.height(); + var w = $container.width(); + var h = $container.height(); canvas.forEachObject(function (obj) { var c = obj.getCoords(); Object.keys(c).forEach(function (k) { From 64596b80976f42f3f8778782befab3053ee5cf65 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 24 Mar 2020 16:16:25 +0100 Subject: [PATCH 08/12] lint compliance --- www/auth/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/auth/main.js b/www/auth/main.js index 65c091695..84a17d922 100644 --- a/www/auth/main.js +++ b/www/auth/main.js @@ -66,7 +66,7 @@ define([ }), { network: network }); - }).nThen(function (waitFor) { + }).nThen(function () { var origin = ApiConfig.fileHost || window.location.origin; // Get contacts and extract their avatar channel and key var getData = function (obj, href) { From 90899aa2f4c8246977d38e4ee9eee5429f2ee1d2 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 24 Mar 2020 13:03:49 -0400 Subject: [PATCH 09/12] start reviewing and removing XXX notes --- lib/commands/pin-rpc.js | 3 ++- lib/compute-index.js | 6 +----- lib/rpc.js | 4 +--- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/commands/pin-rpc.js b/lib/commands/pin-rpc.js index 4aaeb7aaf..cda482d6b 100644 --- a/lib/commands/pin-rpc.js +++ b/lib/commands/pin-rpc.js @@ -547,8 +547,9 @@ const deferResponse = function (Env, channel, cb) { }; */ +// FIXME this will be removed from the client Pinning.isChannelPinned = function (Env, channel, cb) { - return void cb(void 0, true); // XXX + return void cb(void 0, true); /* // if the pins are fully loaded then you can answer yes/no definitively if (Env.pinsLoaded) { diff --git a/lib/compute-index.js b/lib/compute-index.js index 7a146e060..6cf0c3657 100644 --- a/lib/compute-index.js +++ b/lib/compute-index.js @@ -22,11 +22,7 @@ const init = function (config, cb) { }; const tryParse = function (Env, str) { - try { - return JSON.parse(str); - } catch (err) { - // XXX - } + try { return JSON.parse(str); } catch (err) { } }; /* computeIndex diff --git a/lib/rpc.js b/lib/rpc.js index 241f77d41..df9deab8c 100644 --- a/lib/rpc.js +++ b/lib/rpc.js @@ -17,7 +17,7 @@ const UNAUTHENTICATED_CALLS = { GET_FILE_SIZE: Pinning.getFileSize, GET_MULTIPLE_FILE_SIZE: Pinning.getMultipleFileSize, GET_DELETED_PADS: Pinning.getDeletedPads, - IS_CHANNEL_PINNED: Pinning.isChannelPinned, + IS_CHANNEL_PINNED: Pinning.isChannelPinned, // FIXME drop this RPC IS_NEW_CHANNEL: Channel.isNewChannel, WRITE_PRIVATE_MESSAGE: Channel.writePrivateMessage, GET_METADATA: Metadata.getMetadata, @@ -198,8 +198,6 @@ RPC.create = function (Env, cb) { updateLimitDaily(); Env.intervals.dailyLimitUpdate = setInterval(updateLimitDaily, 24*3600*1000); - //Pinning.loadChannelPins(Env); // XXX - // expire old sessions once per minute Env.intervals.sessionExpirationInterval = setInterval(function () { Core.expireSessions(Sessions); From e128683ffb66c1c8e5d822c5c5b7bf38dfaca76b Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 24 Mar 2020 13:31:03 -0400 Subject: [PATCH 10/12] call back with errors instead of throwing within the Storage module --- lib/compute-index.js | 3 ++- lib/historyKeeper.js | 6 ++++-- lib/log.js | 5 ++++- lib/storage/file.js | 13 ++++++++----- scripts/diagnose-archive-conflicts.js | 6 +++++- scripts/evict-inactive.js | 6 +++++- scripts/restore-archived.js | 3 ++- 7 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/compute-index.js b/lib/compute-index.js index 6cf0c3657..b246b0c9c 100644 --- a/lib/compute-index.js +++ b/lib/compute-index.js @@ -15,7 +15,8 @@ const init = function (config, cb) { return void cb('E_INVALID_CONFIG'); } - Store.create(config, function (_store) { + Store.create(config, function (err, _store) { + if (err) { return void cb(err); } store = _store; cb(); }); diff --git a/lib/historyKeeper.js b/lib/historyKeeper.js index 23dbf5fd1..2f6043dfd 100644 --- a/lib/historyKeeper.js +++ b/lib/historyKeeper.js @@ -215,12 +215,14 @@ module.exports.create = function (config, cb) { // create a pin store Store.create({ filePath: pinPath, - }, w(function (s) { + }, w(function (err, s) { + if (err) { throw err; } Env.pinStore = s; })); // create a channel store - Store.create(config, w(function (_store) { + Store.create(config, w(function (err, _store) { + if (err) { throw err; } config.store = _store; Env.msgStore = _store; // API used by rpc Env.store = _store; // API used by historyKeeper diff --git a/lib/log.js b/lib/log.js index 756da8734..d4ffcad56 100644 --- a/lib/log.js +++ b/lib/log.js @@ -101,7 +101,10 @@ Logger.create = function (config, cb) { Store.create({ filePath: config.logPath, - }, function (store) { + }, function (err, store) { + if (err) { + throw err; + } ctx.store = store; var logger = createMethods(ctx); logger.shutdown = function () { diff --git a/lib/storage/file.js b/lib/storage/file.js index 25ff021f0..e040bf807 100644 --- a/lib/storage/file.js +++ b/lib/storage/file.js @@ -951,7 +951,9 @@ var trimChannel = function (env, channelName, hash, _cb) { }); }; -module.exports.create = function (conf, cb) { +module.exports.create = function (conf, _cb) { + var cb = Util.once(Util.mkAsync(_cb)); + var env = { root: conf.filePath || './datastore', archiveRoot: conf.archivePath || './data/archive', @@ -984,18 +986,19 @@ module.exports.create = function (conf, cb) { // make sure the store's directory exists Fse.mkdirp(env.root, PERMISSIVE, w(function (err) { if (err && err.code !== 'EEXIST') { - throw err; // XXX + w.abort(); + return void cb(err); } })); // make sure the cold storage directory exists Fse.mkdirp(env.archiveRoot, PERMISSIVE, w(function (err) { if (err && err.code !== 'EEXIST') { - throw err; // XXX + w.abort(); + return void cb(err); } })); }).nThen(function () { - // XXX leave a place for an error - cb({ + cb(void 0, { // OLDER METHODS // write a new message to a log message: function (channelName, content, cb) { diff --git a/scripts/diagnose-archive-conflicts.js b/scripts/diagnose-archive-conflicts.js index 0e75f4abe..7e5ee92bc 100644 --- a/scripts/diagnose-archive-conflicts.js +++ b/scripts/diagnose-archive-conflicts.js @@ -8,7 +8,11 @@ var Log; nThen(function (w) { // load the store which will be used for iterating over channels // and performing operations like archival and deletion - Store.create(config, w(function (_) { + Store.create(config, w(function (err, _) { + if (err) { + w.abort(); + throw err; + } store = _; })); diff --git a/scripts/evict-inactive.js b/scripts/evict-inactive.js index 18730fd1e..a3a595ca4 100644 --- a/scripts/evict-inactive.js +++ b/scripts/evict-inactive.js @@ -34,7 +34,11 @@ var msSinceStart = function () { nThen(function (w) { // load the store which will be used for iterating over channels // and performing operations like archival and deletion - Store.create(config, w(function (_) { + Store.create(config, w(function (err, _) { + if (err) { + w.abort(); + throw err; + } store = _; })); // load the list of pinned files so you know which files // should not be archived or deleted diff --git a/scripts/restore-archived.js b/scripts/restore-archived.js index 3f68b607e..4ee01c02f 100644 --- a/scripts/restore-archived.js +++ b/scripts/restore-archived.js @@ -8,7 +8,8 @@ var Log; nThen(function (w) { // load the store which will be used for iterating over channels // and performing operations like archival and deletion - Store.create(config, w(function (_) { + Store.create(config, w(function (err, _) { + if (err) { throw err; } store = _; })); From facc6d877acbd87ee620ba62f679b93c7de3833f Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 24 Mar 2020 18:36:55 +0100 Subject: [PATCH 11/12] Remove hardcoded translation key --- www/profile/inner.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/www/profile/inner.js b/www/profile/inner.js index 5dfbaf491..ba348d829 100644 --- a/www/profile/inner.js +++ b/www/profile/inner.js @@ -457,9 +457,9 @@ define([ APP.editor.save(); }; - Messages.profile_copyKey = "Copy edPublic key"; // XXX var addPublicKey = function ($container) { if (!APP.readOnly) { return; } + if (!Messages.profile_copyKey) { return; } // XXX var $div = $(h('div.cp-sidebarlayout-element')).appendTo($container); APP.$edPublic = $('