move hashChannelList into common-hash.js
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
define([
|
||||
'/common/rpc.js',
|
||||
'/bower_components/tweetnacl/nacl-fast.min.js'
|
||||
], function (Rpc) {
|
||||
var Nacl = window.nacl;
|
||||
|
||||
var create = function (network, proxy, cb) {
|
||||
if (!network) {
|
||||
window.setTimeout(function () {
|
||||
@@ -41,21 +38,28 @@ define([
|
||||
|
||||
// you can ask the server to pin a particular channel for you
|
||||
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);
|
||||
};
|
||||
|
||||
// you can also ask to unpin a particular channel
|
||||
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);
|
||||
};
|
||||
|
||||
// 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
|
||||
exp.getServerHash = function (cb) {
|
||||
rpc.send('GET_HASH', edPublic, function (e, hash) {
|
||||
@@ -67,8 +71,15 @@ define([
|
||||
};
|
||||
|
||||
// if local and remote hashes don't match, send a reset
|
||||
exp.reset = function (list, cb) {
|
||||
rpc.send('RESET', list, function (e, response) {
|
||||
exp.reset = 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('RESET', channels, function (e, response) {
|
||||
cb(e, response[0]);
|
||||
});
|
||||
};
|
||||
@@ -81,7 +92,12 @@ define([
|
||||
// get the combined size of all channels (in bytes) for all the
|
||||
// channels which the server has pinned for your publicKey
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user