embark/lib/modules/ipfs/embarkjs/name.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-07-27 11:29:15 +00:00
/*global __embarkIPFS*/
2018-07-30 11:49:03 +00:00
const NoConnectionError = 'No IPFS connection. Please ensure to call Embark.Names.setProvider()';
const NotAvailableError = 'Not available with ipns';
2018-07-27 09:51:17 +00:00
__embarkIPFS.resolve = function (name, callback) {
callback = callback || function () {};
if (!this._ipfsConnection) {
2018-07-30 11:49:03 +00:00
var connectionError = new Error(NoConnectionError);
2018-07-27 09:51:17 +00:00
return callback(connectionError);
}
2018-07-27 11:21:52 +00:00
this._ipfsConnection.name.resolve(name)
.then(res => {
callback(null, res.Path);
})
.catch(() => {
2018-07-30 11:49:03 +00:00
callback(name + " is not registered");
2018-07-27 11:21:52 +00:00
});
2018-07-27 09:51:17 +00:00
};
2018-07-30 11:49:03 +00:00
__embarkIPFS.register = function(addr, callback) {
2018-07-30 11:52:48 +00:00
callback = callback || function () {};
2018-07-27 09:51:17 +00:00
if (!this._ipfsConnection) {
2018-07-30 11:49:03 +00:00
return new Error(NoConnectionError);
2018-07-27 09:51:17 +00:00
}
2018-07-30 11:49:03 +00:00
this._ipfsConnection.name.publish("/ipfs/" + addr)
.then(res => {
callback(null, res.Name);
})
.catch(() => {
callback(addr + " could not be registered");
});
2018-07-27 09:51:17 +00:00
};
__embarkIPFS.lookup = function () {
2018-07-30 11:49:03 +00:00
return new Error(NotAvailableError);
};
__embarkIPFS.registerSubDomain = function () {
return new Error(NotAvailableError);
2018-07-27 09:51:17 +00:00
};