From 2dc7438cbadfd6e284dc35e808a38b53353f7813 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 23 Dec 2020 11:55:54 +0100 Subject: [PATCH 1/3] Fix invalid LKH in roster --- www/common/outer/roster.js | 18 +++++++++++++----- www/common/outer/team.js | 6 +++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/www/common/outer/roster.js b/www/common/outer/roster.js index 2c2675037..7dbf544c2 100644 --- a/www/common/outer/roster.js +++ b/www/common/outer/roster.js @@ -1,5 +1,5 @@ (function () { -var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) { +var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto, Feedback) { var Roster = {}; // this constant is somewhat arbitrary. @@ -587,6 +587,11 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) { // deleted while you are open // emit an event var onChannelError = function (info) { + Feedback.send('ROSTER_CHANNEL_ERROR='+info.type); + if (info.type === "EUNKNOWN") { + // chainpad-netflux should recover by itself + return; + } if (!ready) { return void cb(info); } console.error("CHANNEL_ERROR", info); }; @@ -870,7 +875,8 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) { require("../../bower_components/chainpad-netflux/chainpad-netflux.js"), require("../../bower_components/json.sortify"), require("nthen"), - require("../../bower_components/chainpad-crypto/crypto") + require("../../bower_components/chainpad-crypto/crypto"), + null // no feedback here ); } else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) { require.config({ paths: { 'json.sortify': '/bower_components/json.sortify/dist/JSON.sortify' } }); @@ -880,16 +886,18 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) { '/bower_components/chainpad-netflux/chainpad-netflux.js', 'json.sortify', '/bower_components/nthen/index.js', - '/bower_components/chainpad-crypto/crypto.js' + '/bower_components/chainpad-crypto/crypto.js', + '/common/common-feedback.js', //'/bower_components/tweetnacl/nacl-fast.min.js', - ], function (Util, Hash, CPNF, Sortify, nThen, Crypto) { + ], function (Util, Hash, CPNF, Sortify, nThen, Crypto, Feedback) { return factory.apply(null, [ Util, Hash, CPNF, Sortify, nThen, - Crypto + Crypto, + Feedback ]); }); } else { diff --git a/www/common/outer/team.js b/www/common/outer/team.js index 38e83608a..cba26189f 100644 --- a/www/common/outer/team.js +++ b/www/common/outer/team.js @@ -1796,7 +1796,11 @@ define([ teams[id].keys.mailbox = deriveMailbox(teams[id]); } openChannel(ctx, teams[id], id, waitFor(function (err) { - if (err) { return void console.error(err); } + if (err) { + var txt = typeof(err) === "string" ? err : (err.type || err.message); + Feedback.send("TEAM_LOADING_ERROR="+txt); + return void console.error(err); + } console.debug('Team '+id+' ready'); })); }); From 588955c1fe41c62d7827cc9280fcd1997a01dc70 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 23 Dec 2020 12:00:17 +0100 Subject: [PATCH 2/3] Fix type error --- www/common/outer/roster.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/common/outer/roster.js b/www/common/outer/roster.js index 7dbf544c2..72f343477 100644 --- a/www/common/outer/roster.js +++ b/www/common/outer/roster.js @@ -587,8 +587,8 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto, Feedback) // deleted while you are open // emit an event var onChannelError = function (info) { - Feedback.send('ROSTER_CHANNEL_ERROR='+info.type); - if (info.type === "EUNKNOWN") { + if (Feedback) { Feedback.send('ROSTER_CHANNEL_ERROR='+(info && info.type)); } + if (info && info.type === "EUNKNOWN") { // chainpad-netflux should recover by itself return; } From fed04a025c1f2daa8cb9e180e3d251721267ab79 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 23 Dec 2020 17:21:06 +0530 Subject: [PATCH 3/3] display size of uploaded files upon completion --- lib/commands/upload.js | 4 +++- lib/workers/db-worker.js | 20 ++++++++++++++------ lib/workers/index.js | 3 ++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/commands/upload.js b/lib/commands/upload.js index 6dc0aa911..346262716 100644 --- a/lib/commands/upload.js +++ b/lib/commands/upload.js @@ -86,6 +86,8 @@ Upload.cancel = function (Env, safeKey, arg, cb) { Upload.complete_owned = function (Env, safeKey, arg, cb) { Env.blobStore.closeBlobstage(safeKey); - Env.completeUpload(safeKey, arg, true, cb); + var user = Core.getSession(Env.Sessions, safeKey); + var size = user.pendingUploadSize; + Env.completeUpload(safeKey, arg, true, size, cb); }; diff --git a/lib/workers/db-worker.js b/lib/workers/db-worker.js index 7f45dfaa2..5750ff7ac 100644 --- a/lib/workers/db-worker.js +++ b/lib/workers/db-worker.js @@ -30,6 +30,11 @@ Logger.levels.forEach(function (level) { }; }); +var DETAIL = 1000; +var round = function (n) { + return Math.floor(n * DETAIL) / DETAIL; +}; + var ready = false; var store; var pinStore; @@ -231,11 +236,11 @@ const computeIndexFromOffset = function (channelName, offset, cb) { Env.Log.info('WORKER_OFFSET_UPDATE', { channel: channelName, start: start, - startMB: start / 1024 / 1024, + startMB: round(start / 1024 / 1024), update: new_start, - updateMB: new_start / 1024 / 1024, + updateMB: round(new_start / 1024 / 1024), diff: diff, - diffMB: diff / 1024 / 1024, + diffMB: round(diff / 1024 / 1024), }); })); }).nThen(function () { @@ -269,7 +274,7 @@ const computeIndex = function (data, cb) { Env.Log.verbose('WORKER_OFFSET_RECOVERY', { channel: channelName, start: start, - startMB: start / 1024 / 1024, + startMB: round(start / 1024 / 1024), }); } })); @@ -544,11 +549,13 @@ const evictInactive = function (data, cb) { Eviction(Env, cb); }; -var reportStatus = function (Env, label, safeKey, err, id) { +var reportStatus = function (Env, label, safeKey, err, id, size) { var data = { safeKey: safeKey, err: err && err.message || err, id: id, + size: size, + sizeMB: round((size || 0) / 1024 / 1024), }; var method = err? 'error': 'info'; Env.Log[method](label, data); @@ -559,6 +566,7 @@ const completeUpload = function (data, cb) { var owned = data.owned; var safeKey = data.safeKey; var arg = data.arg; + var size = data.size; var method; var label; @@ -571,7 +579,7 @@ const completeUpload = function (data, cb) { } Env.blobStore[method](safeKey, arg, function (err, id) { - reportStatus(Env, label, safeKey, err, id); + reportStatus(Env, label, safeKey, err, id, size); cb(err, id); }); }; diff --git a/lib/workers/index.js b/lib/workers/index.js index c422a9f54..25c18d947 100644 --- a/lib/workers/index.js +++ b/lib/workers/index.js @@ -434,12 +434,13 @@ Workers.initialize = function (Env, config, _cb) { }, cb); }; - Env.completeUpload = function (safeKey, arg, owned, cb) { + Env.completeUpload = function (safeKey, arg, owned, size, cb) { sendCommand({ command: "COMPLETE_UPLOAD", owned: owned, // Boolean safeKey: safeKey, // String (public key) arg: arg, // String (file id) + size: size, // Number || undefined }, cb); };