2018-07-27 09:51:17 +00:00
|
|
|
__embarkIPFS.resolve = function (name, callback) {
|
|
|
|
callback = callback || function () {};
|
|
|
|
if (!this._ipfsConnection) {
|
|
|
|
var connectionError = new Error('No IPFS connection. Please ensure to call Embark.Names.setProvider()');
|
|
|
|
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-27 09:51:17 +00:00
|
|
|
return callback(name + " is not registered");
|
2018-07-27 11:21:52 +00:00
|
|
|
});
|
2018-07-27 09:51:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
__embarkIPFS.register = function(addr, options) {
|
|
|
|
if (!this._ipfsConnection) {
|
|
|
|
return new Error('No IPFS connection. Please ensure to call Embark.Names.setProvider()');
|
|
|
|
}
|
|
|
|
|
2018-07-27 11:21:52 +00:00
|
|
|
this._ipfsConnection.name.publish("/ipfs/" + addr, options)
|
|
|
|
.then(res => {
|
|
|
|
return `https://gateway.ipfs.io/ipns/${res.name}`;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
return new Error('Unexpected Error: ' + err);
|
|
|
|
});
|
2018-07-27 09:51:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
__embarkIPFS.lookup = function () {
|
|
|
|
return new Error("Not Implemented");
|
|
|
|
};
|