Merge branch 'staging' of github.com:xwiki-labs/cryptpad into staging

This commit is contained in:
yflory 2017-06-30 11:42:59 +02:00
commit 26193aeaa7
5 changed files with 61 additions and 11 deletions

View File

@ -277,6 +277,11 @@ module.exports = {
*/
//logFeedback: true,
/* If you wish to see which remote procedure calls clients request,
* set this to true
*/
//logRPC: true,
/* it is recommended that you serve CryptPad over https
* the filepaths below are used to configure your certificates
*/

1
rpc.js
View File

@ -944,6 +944,7 @@ RPC.create = function (config /*:typeof(ConfigType)*/, cb /*:(?Error, ?Function)
if (!Env.msgStore) { Env.msgStore = ctx.store; }
var handleMessage = function (privileged) {
if (config.logRPC) { console.log(msg[0]); }
switch (msg[0]) {
case 'COOKIE': return void Respond(void 0);
case 'RESET':

View File

@ -135,6 +135,25 @@ define([], function () {
return g;
};
/* takes a function (f) and a time (t) in ms. returns a function wrapper
which prevents the internal function from being called more than once
every t ms. if the function is prevented, returns time til next valid
execution, else null.
*/
Util.notAgainForAnother = function (f, t) {
if (typeof(f) !== 'function' || typeof(t) !== 'number') {
throw new Error("invalid inputs");
}
var last = null;
return function () {
var now = +new Date();
if (last && now <= last + t) { return t - (now - last); }
last = now;
f();
return null;
};
};
Util.createRandomInteger = function () {
return Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
};

View File

@ -84,6 +84,7 @@ define([
common.throttle = Util.throttle;
common.createRandomInteger = Util.createRandomInteger;
common.getAppType = Util.getAppType;
common.notAgainForAnother = Util.notAgainForAnother;
// import hash utilities for export
var createRandomHash = common.createRandomHash = Hash.createRandomHash;
@ -848,19 +849,28 @@ define([
rpc.uploadCancel(cb);
};
/* Create a usage bar which keeps track of how much storage space is used
by your CryptDrive. The getPinnedUsage RPC is one of the heavier calls,
so we throttle its usage. Clients will not update more than once per
LIMIT_REFRESH_RATE. It will be update at least once every three such intervals
If changes are made to your drive in the interim, they will trigger an
update.
*/
var LIMIT_REFRESH_RATE = 30000; // milliseconds
common.createUsageBar = function (cb) {
// getPinnedUsage updates common.account.usage, and other values
// so we can just use those and only check for errors
var $container = $('<span>', {'class':'limit-container'});
var todo = function (err) {
$container.html('');
if (err) {
return void window.setTimeout(function () {
common.getPinnedUsage(todo);
}, LIMIT_REFRESH_RATE);
}
var todo;
var updateUsage = window.updateUsage = common.notAgainForAnother(function () {
console.log("updating usage bar");
common.getPinnedUsage(todo);
}, LIMIT_REFRESH_RATE);
todo = function (err) {
if (err) { return void console.error(err); }
$container.html('');
var unit = Util.magnitudeOfBytes(common.account.limit);
var usage = unit === 'GB'? Util.bytesToGigabytes(common.account.usage):
@ -920,11 +930,25 @@ define([
var $text = $('<span>', {'class': 'usageText'});
$text.text(usage + ' / ' + prettyLimit);
$limit.append($usage).append($text);
window.setTimeout(function () {
common.getPinnedUsage(todo);
}, LIMIT_REFRESH_RATE);
};
common.getPinnedUsage(todo);
setInterval(function () {
var t = updateUsage();
if (t) {
console.log("usage already updated. eligible for refresh in %sms", t);
}
}, LIMIT_REFRESH_RATE * 3);
updateUsage();
getProxy().on('change', ['drive'], function () {
var t = updateUsage();
if (t) {
console.log("usage bar update throttled due to overuse." +
" Eligible for update in %sms", t);
} else {
console.log("usage bar updated");
}
});
cb(null, $container);
};

View File

@ -465,6 +465,7 @@ define([
window.frames["pad-iframe"].print();
}
}, {ok: Messages.printButton});
Cryptpad.feedback('PRINT_SLIDES');
//$('body').append(createPrintDialog());
}).append($('<span>', {'class': 'drawer'}).text(Messages.printText));
$drawer.append($printButton);