From 8e4b6a6383cf3882eebc48dd4e40258a3d300392 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 9 Sep 2019 15:52:04 +0200 Subject: [PATCH 1/9] change the log type on noisy messages for easier filtering --- www/common/LessLoader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/common/LessLoader.js b/www/common/LessLoader.js index d9e7d3078..4817d5a25 100644 --- a/www/common/LessLoader.js +++ b/www/common/LessLoader.js @@ -165,7 +165,7 @@ define([ stack.push(url); cacheGet(url, function (css) { if (css) { return void loadSubmodulesAndInject(css, url, done, stack); } - console.log('CACHE MISS ' + url); + console.debug('CACHE MISS ' + url); ((/\.less([\?\#].*)?$/.test(url)) ? loadLess : loadCSS)(url, function (err, css) { if (!css) { return void console.error(err); } var output = fixAllURLs(css, url); From c7cea7fae3682f55b8c71f9afd3bfcb81455d12f Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 9 Sep 2019 15:56:01 +0200 Subject: [PATCH 2/9] identify cause of 'channel ready without callback' and handle reconnection more gracefully --- www/common/common-messenger.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/www/common/common-messenger.js b/www/common/common-messenger.js index 1210e652f..be4fa9aa2 100644 --- a/www/common/common-messenger.js +++ b/www/common/common-messenger.js @@ -728,6 +728,15 @@ define([ network.on('reconnect', function () { if (channel && channel.stopped) { return; } if (!channels[data.channel]) { return; } + + if (!joining[data.channel]) { + joining[data.channel] = function () { + console.log("reconnected to %s", data.channel); + }; + } else { + console.error("Reconnected to a chat channel (%s) which was not fully connected", data.channel); + } + network.join(data.channel).then(onOpen, function (err) { console.error(err); }); From c9be2fae363c9adce794243098b39bc5e99431e1 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 9 Sep 2019 15:59:56 +0200 Subject: [PATCH 3/9] avoid triggering a warning when using the Notifications API in an insecure context --- www/common/notify.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/common/notify.js b/www/common/notify.js index 5109e8748..dc5c19ad5 100644 --- a/www/common/notify.js +++ b/www/common/notify.js @@ -6,7 +6,7 @@ define(['/api/config'], function (ApiConfig) { var isSupported = Module.isSupported = function () { - return typeof(window.Notification) === 'function'; + return typeof(window.Notification) === 'function' && window.location.protocol === 'https:'; }; var hasPermission = Module.hasPermission = function () { From d83c43b0ebe2cc850ebcb3f62f18f20a69c7da6a Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 9 Sep 2019 16:00:59 +0200 Subject: [PATCH 4/9] increment version to 3.1.0 --- customize.dist/pages.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/customize.dist/pages.js b/customize.dist/pages.js index 9791e83f0..bd373b04c 100644 --- a/customize.dist/pages.js +++ b/customize.dist/pages.js @@ -103,7 +103,7 @@ define([ ])*/ ]) ]), - h('div.cp-version-footer', "CryptPad v3.0.1 (Aurochs' revenge)") + h('div.cp-version-footer', "CryptPad v3.1.0 (Baiji)") ]); }; diff --git a/package.json b/package.json index f14fda1aa..fdbbc008a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cryptpad", "description": "realtime collaborative visual editor with zero knowlege server", - "version": "3.0.1", + "version": "3.1.0", "license": "AGPL-3.0+", "repository": { "type": "git", From 1d5534b593b9dd4ab8fb63026071e062e4024820 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 9 Sep 2019 16:03:14 +0200 Subject: [PATCH 5/9] provide more debugging info on metadata parse errors --- storage/file.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/file.js b/storage/file.js index 904e07e38..52b1d38e9 100644 --- a/storage/file.js +++ b/storage/file.js @@ -76,7 +76,7 @@ var getMetadataAtPath = function (Env, path, cb) { catch (e) { console.log("getMetadataAtPath"); console.error(e); - complete('INVALID_METADATA'); + complete('INVALID_METADATA', metadata); } }); stream.on('end', function () { From 56ec91ff275e9ecbc27371cf638531b742bcca6b Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 9 Sep 2019 16:30:58 +0200 Subject: [PATCH 6/9] update util.once to add a handler for multiple callbacks --- www/common/common-util.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/www/common/common-util.js b/www/common/common-util.js index 580b9f539..ba70b0ceb 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -222,13 +222,14 @@ return Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); }; + Util.noop = function () {}; + /* for wrapping async functions such that they can only be called once */ - Util.once = function (f) { - var called; + Util.once = function (f, g) { return function () { - if (called) { return; } - called = true; + if (!f) { return; } f.apply(this, Array.prototype.slice.call(arguments)); + f = g; }; }; From 40f302d0028d34f0e01e70013307b9fefbbf5af3 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 9 Sep 2019 16:34:30 +0200 Subject: [PATCH 7/9] revert usage of batch reads for file size --- rpc.js | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/rpc.js b/rpc.js index 71e267dfd..c382a275a 100644 --- a/rpc.js +++ b/rpc.js @@ -294,37 +294,33 @@ var getUploadSize = function (Env, channel, cb) { // FIXME FILES }); }; -const batchFileSize = BatchRead("GET_FILE_SIZE"); var getFileSize = function (Env, channel, cb) { if (!isValidId(channel)) { return void cb('INVALID_CHAN'); } - batchFileSize(channel, cb, function (done) { - if (channel.length === 32) { - if (typeof(Env.msgStore.getChannelSize) !== 'function') { - return done('GET_CHANNEL_SIZE_UNSUPPORTED'); - } - - return void Env.msgStore.getChannelSize(channel, function (e, size /*:number*/) { - if (e) { - if (e.code === 'ENOENT') { return void done(void 0, 0); } - return void done(e.code); - } - done(void 0, size); - }); + if (channel.length === 32) { + if (typeof(Env.msgStore.getChannelSize) !== 'function') { + return cb('GET_CHANNEL_SIZE_UNSUPPORTED'); } - // 'channel' refers to a file, so you need another API - getUploadSize(Env, channel, function (e, size) { - if (typeof(size) === 'undefined') { return void done(e); } - done(void 0, size); + return void Env.msgStore.getChannelSize(channel, function (e, size /*:number*/) { + if (e) { + if (e.code === 'ENOENT') { return void cb(void 0, 0); } + return void cb(e.code); + } + cb(void 0, size); }); + } + + // 'channel' refers to a file, so you need another API + getUploadSize(Env, channel, function (e, size) { + if (typeof(size) === 'undefined') { return void cb(e); } + cb(void 0, size); }); }; const batchMetadata = BatchRead("GET_METADATA"); var getMetadata = function (Env, channel, cb) { if (!isValidId(channel)) { return void cb('INVALID_CHAN'); } - - if (channel.length !== 32) { return cb("INVALID_CHAN"); } + if (channel.length !== 32) { return cb("INVALID_CHAN_LENGTH"); } batchMetadata(channel, cb, function (done) { var ref = {}; From a3eff2728e80d260c692aa4ec6b9db8b6683622a Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 9 Sep 2019 16:39:54 +0200 Subject: [PATCH 8/9] update lib/once.js to match clientside definition --- lib/once.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/once.js b/lib/once.js index 369ee162e..a851af259 100644 --- a/lib/once.js +++ b/lib/once.js @@ -1,8 +1,7 @@ -module.exports = function (f) { - var called; +module.exports = function (f, g) { return function () { - if (called) { return; } - called = true; + if (!f) { return; } f.apply(this, Array.prototype.slice.call(arguments)); + f = g; }; }; From 26faf72df8fbb857bd0bcaa9ca21eeb0934133df Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 9 Sep 2019 17:23:35 +0200 Subject: [PATCH 9/9] make it easier to filter clientside logs --- www/common/LessLoader.js | 2 +- www/common/cryptpad-common.js | 2 +- www/common/notify.js | 2 +- www/common/sframe-common-mailbox.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/www/common/LessLoader.js b/www/common/LessLoader.js index 4817d5a25..c04006e12 100644 --- a/www/common/LessLoader.js +++ b/www/common/LessLoader.js @@ -158,7 +158,7 @@ define([ var done = function () { clearTimeout(timeout); if (btime) { - console.log("Compiling [" + url + "] took " + (+new Date() - btime) + "ms"); + console.info("Compiling [" + url + "] took " + (+new Date() - btime) + "ms"); } cb(); }; diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 1cdfda3e9..e51a0b8be 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -1346,7 +1346,7 @@ define([ console.log(parsed); return; } else { - console.log(parsed); + //console.log(parsed); } Util.fetch(parsed.href, waitFor(function (err, arraybuffer) { if (err) { return void console.log(err); } diff --git a/www/common/notify.js b/www/common/notify.js index dc5c19ad5..5b49de991 100644 --- a/www/common/notify.js +++ b/www/common/notify.js @@ -52,7 +52,7 @@ define(['/api/config'], function (ApiConfig) { }; var createFavicon = function () { - console.log("creating favicon"); + console.debug("creating favicon"); var fav = document.createElement('link'); var attrs = { id: 'favicon', diff --git a/www/common/sframe-common-mailbox.js b/www/common/sframe-common-mailbox.js index e468b29f1..a988ef003 100644 --- a/www/common/sframe-common-mailbox.js +++ b/www/common/sframe-common-mailbox.js @@ -126,7 +126,7 @@ define([ var onMessage = function (data) { // data = { type: 'type', content: {msg: 'msg', hash: 'hash'} } - console.log(data.type, data.content); + console.debug(data.type, data.content); pushMessage(data); if (!history[data.type]) { history[data.type] = []; } history[data.type].push(data.content);