mirror of https://github.com/xwiki-labs/cryptpad
add nodejs support to pinpad.js
This commit is contained in:
parent
be8b014b36
commit
2c0e03a3d4
|
@ -1,29 +1,16 @@
|
||||||
define([
|
(function () {
|
||||||
'/common/rpc.js',
|
var factory = function (Util, Rpc) {
|
||||||
], function (Rpc) {
|
var create = function (network, proxy, _cb) {
|
||||||
var create = function (network, proxy, cb) {
|
if (typeof(_cb) !== 'function') { throw new Error("Expected callback"); }
|
||||||
if (!network) {
|
var cb = Util.once(Util.mkAsync(_cb));
|
||||||
setTimeout(function () {
|
|
||||||
cb('INVALID_NETWORK');
|
if (!network) { return void cb('INVALID_NETWORK'); }
|
||||||
});
|
if (!proxy) { return void cb('INVALID_PROXY'); }
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!proxy) {
|
|
||||||
setTimeout(function () {
|
|
||||||
cb('INVALID_PROXY');
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var edPrivate = proxy.edPrivate;
|
var edPrivate = proxy.edPrivate;
|
||||||
var edPublic = proxy.edPublic;
|
var edPublic = proxy.edPublic;
|
||||||
|
|
||||||
if (!(edPrivate && edPublic)) {
|
if (!(edPrivate && edPublic)) { return void cb('INVALID_KEYS'); }
|
||||||
setTimeout(function () {
|
|
||||||
cb('INVALID_KEYS');
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Rpc.create(network, edPrivate, edPublic, function (e, rpc) {
|
Rpc.create(network, edPrivate, edPublic, function (e, rpc) {
|
||||||
if (e) { return void cb(e); }
|
if (e) { return void cb(e); }
|
||||||
|
@ -76,7 +63,7 @@ define([
|
||||||
if (!(hash && hash[0])) {
|
if (!(hash && hash[0])) {
|
||||||
return void cb('NO_HASH_RETURNED');
|
return void cb('NO_HASH_RETURNED');
|
||||||
}
|
}
|
||||||
cb(e, hash[0]);
|
cb(e, Array.isArray(hash) && hash[0] || undefined);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -275,4 +262,10 @@ define([
|
||||||
};
|
};
|
||||||
|
|
||||||
return { create: create };
|
return { create: create };
|
||||||
});
|
};
|
||||||
|
if (typeof(module) !== 'undefined' && module.exports) {
|
||||||
|
module.exports = factory(require('./common-util'), require("./rpc"));
|
||||||
|
} else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) {
|
||||||
|
define([ '/common/common-util.js', '/common/rpc.js', ], function (Util, Rpc) { return factory(Util, Rpc); });
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
|
Loading…
Reference in New Issue