cryptpad/www/examples/pin/main.js

51 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-04-04 10:25:34 +00:00
define([
'jquery',
2017-04-04 10:25:34 +00:00
'/common/cryptpad-common.js',
'/common/pinpad.js'
], function ($, Cryptpad, Pinpad) {
2017-05-04 14:16:09 +00:00
window.APP = {
2017-04-04 10:25:34 +00:00
Cryptpad: Cryptpad,
};
2017-04-05 15:28:04 +00:00
var synchronize = function (call) {
// provide a sorted list of unique channels
2017-04-07 13:52:34 +00:00
var list = Cryptpad.getCanonicalChannelList();
var localHash = call.hashChannelList(list);
2017-04-05 15:28:04 +00:00
var serverHash;
2017-04-07 08:32:26 +00:00
call.getFileListSize(function (e, bytes) {
if (e) { return void console.error(e); }
console.log("total %sK bytes used", bytes / 1000);
2017-04-07 08:32:26 +00:00
});
2017-04-05 15:28:04 +00:00
call.getServerHash(function (e, hash) {
if (e) { return void console.error(e); }
serverHash = hash;
if (serverHash === localHash) {
return console.log("all your pads are pinned. There is nothing to do");
}
call.reset(list, function (e, response) {
2017-04-05 15:28:04 +00:00
if (e) { return console.error(e); }
2017-04-07 09:37:19 +00:00
else {
return console.log('reset pin list. new hash is [%s]', response);
}
2017-04-05 15:28:04 +00:00
});
});
};
2017-04-04 10:25:34 +00:00
$(function () {
2017-05-04 14:16:09 +00:00
Cryptpad.ready(function () {
var network = Cryptpad.getNetwork();
var proxy = Cryptpad.getStore().getProxy().proxy;
Pinpad.create(network, proxy, function (e, call) {
2017-04-04 10:25:34 +00:00
if (e) { return void console.error(e); }
2017-04-05 15:28:04 +00:00
synchronize(call);
2017-04-04 10:25:34 +00:00
});
});
});
});