|
|
@ -1,9 +1,6 @@
|
|
|
|
define([
|
|
|
|
define([
|
|
|
|
'/common/rpc.js',
|
|
|
|
'/common/rpc.js',
|
|
|
|
'/bower_components/tweetnacl/nacl-fast.min.js'
|
|
|
|
|
|
|
|
], function (Rpc) {
|
|
|
|
], function (Rpc) {
|
|
|
|
var Nacl = window.nacl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var create = function (network, proxy, cb) {
|
|
|
|
var create = function (network, proxy, cb) {
|
|
|
|
if (!network) {
|
|
|
|
if (!network) {
|
|
|
|
window.setTimeout(function () {
|
|
|
|
window.setTimeout(function () {
|
|
|
@ -41,21 +38,28 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
// you can ask the server to pin a particular channel for you
|
|
|
|
// you can ask the server to pin a particular channel for you
|
|
|
|
exp.pin = function (channels, cb) {
|
|
|
|
exp.pin = function (channels, cb) {
|
|
|
|
|
|
|
|
// TODO use isArray if it's safe
|
|
|
|
|
|
|
|
if (!channels && channels.length) {
|
|
|
|
|
|
|
|
window.setTimeout(function () {
|
|
|
|
|
|
|
|
cb('[TypeError] pin expects an array');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
rpc.send('PIN', channels, cb);
|
|
|
|
rpc.send('PIN', channels, cb);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// you can also ask to unpin a particular channel
|
|
|
|
// you can also ask to unpin a particular channel
|
|
|
|
exp.unpin = function (channels, cb) {
|
|
|
|
exp.unpin = function (channels, cb) {
|
|
|
|
|
|
|
|
// TODO use isArray if it's safe
|
|
|
|
|
|
|
|
if (!channels && channels.length) {
|
|
|
|
|
|
|
|
window.setTimeout(function () {
|
|
|
|
|
|
|
|
cb('[TypeError] pin expects an array');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
rpc.send('UNPIN', channels, cb);
|
|
|
|
rpc.send('UNPIN', channels, cb);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// This implementation must match that on the server
|
|
|
|
|
|
|
|
// it's used for a checksum
|
|
|
|
|
|
|
|
exp.hashChannelList = function (list) {
|
|
|
|
|
|
|
|
return Nacl.util.encodeBase64(Nacl.hash(Nacl.util
|
|
|
|
|
|
|
|
.decodeUTF8(JSON.stringify(list))));
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ask the server what it thinks your hash is
|
|
|
|
// ask the server what it thinks your hash is
|
|
|
|
exp.getServerHash = function (cb) {
|
|
|
|
exp.getServerHash = function (cb) {
|
|
|
|
rpc.send('GET_HASH', edPublic, function (e, hash) {
|
|
|
|
rpc.send('GET_HASH', edPublic, function (e, hash) {
|
|
|
@ -67,8 +71,15 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// if local and remote hashes don't match, send a reset
|
|
|
|
// if local and remote hashes don't match, send a reset
|
|
|
|
exp.reset = function (list, cb) {
|
|
|
|
exp.reset = function (channels, cb) {
|
|
|
|
rpc.send('RESET', list, function (e, response) {
|
|
|
|
// TODO use isArray if it's safe
|
|
|
|
|
|
|
|
if (!channels && channels.length) {
|
|
|
|
|
|
|
|
window.setTimeout(function () {
|
|
|
|
|
|
|
|
cb('[TypeError] pin expects an array');
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
rpc.send('RESET', channels, function (e, response) {
|
|
|
|
cb(e, response[0]);
|
|
|
|
cb(e, response[0]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -81,7 +92,12 @@ define([
|
|
|
|
// get the combined size of all channels (in bytes) for all the
|
|
|
|
// get the combined size of all channels (in bytes) for all the
|
|
|
|
// channels which the server has pinned for your publicKey
|
|
|
|
// channels which the server has pinned for your publicKey
|
|
|
|
exp.getFileListSize = function (cb) {
|
|
|
|
exp.getFileListSize = function (cb) {
|
|
|
|
rpc.send('GET_TOTAL_SIZE', undefined, cb);
|
|
|
|
rpc.send('GET_TOTAL_SIZE', undefined, function (e, response) {
|
|
|
|
|
|
|
|
if (e) { return void cb(e); }
|
|
|
|
|
|
|
|
if (response && response.length) {
|
|
|
|
|
|
|
|
cb(void 0, response[0]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
cb(e, exp);
|
|
|
|
cb(e, exp);
|
|
|
|