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

This commit is contained in:
yflory
2017-04-07 14:54:13 +02:00
8 changed files with 130 additions and 233 deletions

View File

@@ -28,34 +28,8 @@ define([
rpc.send('GET_FILE_SIZE', file, cb);
};
var getFileListSize = function (rpc, list, cb) {
var bytes = 0;
var left = list.length;
list.forEach(function (chan) {
getFileSize(rpc, chan, function (e, msg) {
if (e) {
if (e === 'ENOENT') {
// these channels no longer exists on the server
console.log(e, chan);
} else {
console.error(e);
}
} else if (msg && msg[0] && typeof(msg[0]) === 'number') {
bytes += msg[0];
//console.log(bytes);
} else {
console.log("returned message was not a number: ", msg);
}
--left;
if (left === 0) {
cb(void 0, bytes);
}
});
});
var getFileListSize = function (rpc, cb) {
return rpc.send('GET_TOTAL_SIZE', undefined, cb);
};
var pinChannel = function (rpc, channel, cb) {
@@ -67,7 +41,8 @@ define([
};
var reset = function (rpc, cb) {
rpc.send('RESET', undefined, cb);
var list = uniqueChannelList();
rpc.send('RESET', list, cb);
};
/*
@@ -80,7 +55,6 @@ define([
UNPIN all, send all
*/
// Don't use create until Cryptpad is ready
// (use Cryptpad.ready)
var create = function (cb) {
@@ -108,8 +82,8 @@ define([
exp.getFileSize = function (file, cb) {
getFileSize(rpc, file, cb);
};
exp.getFileListSize = function (list, cb) {
getFileListSize(rpc, list, cb);
exp.getFileListSize = function (cb) {
getFileListSize(rpc, cb);
};
exp.getServerHash = function (cb) {
getServerHash(rpc, edPublic, cb);

View File

@@ -36,11 +36,6 @@ define([
console.log(msg);
});
}
call.getFileListSize(list, function (e, bytes) {
if (e) { return void console.error(e); }
console.log("%s total bytes used", bytes);
});
call.getServerHash(function (e, hash) {
if (e) { return void console.error(e); }
console.log("the server believes your user hash is [%s]", hash);
@@ -51,6 +46,11 @@ define([
var localHash = call.localChannelsHash();
var serverHash;
call.getFileListSize(function (e, bytes) {
if (e) { return void console.error(e); }
console.log("%s total bytes used", bytes);
});
call.getServerHash(function (e, hash) {
if (e) { return void console.error(e); }
serverHash = hash;
@@ -61,15 +61,9 @@ define([
call.reset(function (e, response) {
if (e) { return console.error(e); }
var list = call.uniqueChannelList();
// now start pinning...
list.forEach(function (channel) {
call.pin(channel, function (e, out) {
if (e) { return console.error(e); }
});
});
else {
return console.log('reset pin list. new hash is [%s]', response);
}
});
/*

View File

@@ -1,13 +0,0 @@
<!DOCTYPE html>
<html class="cp slide">
<head>
<title>CryptPad</title>
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
<script data-bootload="main.js" data-main="/common/boot.js" src="/bower_components/requirejs/require.js"></script>
</head>
<body>
<div id="iframe-container">
<iframe id="pad-iframe"></iframe><script src="/common/noscriptfix.js"></script>
</div>
</body>
</html>

View File

@@ -1,8 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<h1>PEWPEW

View File

@@ -1,111 +0,0 @@
require.config({ paths: { 'json.sortify': '/bower_components/json.sortify/dist/JSON.sortify' } });
define([
'/common/cryptpad-common.js',
'/common/rpc.js',
'/bower_components/jquery/dist/jquery.min.js',
], function (Cryptpad, RPC) {
var $ = window.jQuery;
var APP = window.APP = {
Cryptpad: Cryptpad,
};
$(function () {
Cryptpad.ready(function (err, env) {
var network = Cryptpad.getNetwork();
var proxy = Cryptpad.getStore().getProxy().proxy;
var edPrivate = proxy.edPrivate;
var edPublic = proxy.edPublic;
var payload = {
a: Math.floor(Math.random() * 1000),
b: 7,
};
RPC.create(network, edPrivate, edPublic, function (e, rpc) {
// console.log(payload);
rpc.send('ECHO', payload, function (e, msg) {
if (e) { return void console.error(e); }
console.log(msg);
});
// test a non-existent RPC call
rpc.send('PEWPEW', ['pew'], function (e, msg) {
if (e) {
if (e === 'UNSUPPORTED_RPC_CALL') { return; }
return void console.error(e);
}
console.log(msg);
});
var list = Cryptpad.getUserChannelList();
if (list.length) {
rpc.send('GET_FILE_SIZE', list[0], function (e, msg) {
if (e) {
return void console.error(e);
}
console.log(msg);
});
}
rpc.send('GET_FILE_SIZE', 'pewpew', function (e, msg) {
if (e) {
if (e === 'INVALID_CHAN') { return; }
return void console.error(e);
}
console.log(msg);
});
rpc.send('GET_FILE_SIZE', '26f014b2ab959418605ea37a6785f317', function (e, msg) {
if (e) {
if (e === 'ENOENT') { return; }
return void console.error(e);
}
console.error("EXPECTED ENOENT");
console.log(msg);
});
(function () {
// compute what you think the hash should be
// then ask the server if what it has matches your records
rpc.send('GET_HASH', edPublic, function (e, hash) {
if (e) { return void console.error(e); }
console.log("user pins hash is [%s]", hash);
// if it does, awesome!
// you should be able to pin and unpin things easily
// if it doesn't, send a reset, and start re-pinning
});
}());
if (false) {
(function () {
var bytes = 0;
list.forEach(function (chan) {
rpc.send('GET_FILE_SIZE', chan, function (e, msg) {
if (e) {
if (e === 'ENOENT') {
return void console.log(e, chan);
}
return void console.error(e);
}
if (msg && msg[0] && typeof(msg[0]) === 'number') {
bytes += msg[0];
console.log(bytes);
} else {
console.log(msg);
}
});
});
}());
}
});
});
});
});

View File

@@ -13,10 +13,11 @@ define([
'/common/cryptpad-common.js',
'/common/visible.js',
'/common/notify.js',
'/customize/application_config.js',
'/bower_components/secure-fabric.js/dist/fabric.min.js',
'/bower_components/jquery/dist/jquery.min.js',
'/bower_components/file-saver/FileSaver.min.js',
], function (Config, Realtime, Crypto, Toolbar, TextPatcher, JSONSortify, JsonOT, Cryptpad, Visible, Notify) {
], function (Config, Realtime, Crypto, Toolbar, TextPatcher, JSONSortify, JsonOT, Cryptpad, Visible, Notify, AppConfig) {
var saveAs = window.saveAs;
var Messages = Cryptpad.Messages;
@@ -102,16 +103,12 @@ define([
$width.on('change', updateBrushWidth);
var pickColor = function (current, cb) {
// TODO find out why initial color is not being set
// http://jsfiddle.net/j3hZB/
console.log(current);
var $picker = $('<input>', {
type: 'color',
value: '#FFFFFF',
})
.css({
visibility: 'hidden'
//display: 'none',
})
.on('change', function () {
var color = this.value;
@@ -140,9 +137,10 @@ define([
return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
};
// TODO add a better color palette
var palette = ['red', 'blue', 'green', 'white', 'black', 'purple',
'gray', 'beige', 'brown', 'cyan', 'darkcyan', 'gold', 'yellow', 'pink'];
var palette = AppConfig.whiteboardPalette || [
'red', 'blue', 'green', 'white', 'black', 'purple',
'gray', 'beige', 'brown', 'cyan', 'darkcyan', 'gold', 'yellow', 'pink'
];
$('.palette-color').on('click', function () {
var color = $(this).css('background-color');