fix ipfs methods

This commit is contained in:
Iuri Matias 2016-10-12 08:20:20 -04:00
parent a8b9630b99
commit fe926382ce
2 changed files with 12 additions and 12 deletions

View File

@ -121,7 +121,7 @@ var EmbarkJS =
EmbarkJS.Storage.setProvider = function(provider, options) { EmbarkJS.Storage.setProvider = function(provider, options) {
if (provider === 'ipfs') { if (provider === 'ipfs') {
this.currentStorage = EmbarkJS.Storage.IPFS; this.currentStorage = EmbarkJS.Storage.IPFS;
this.ipfsConnection = Ipfs(options.server, options.port); this.ipfsConnection = IpfsApi(options.server, options.port);
} else { } else {
throw Error('unknown provider'); throw Error('unknown provider');
} }
@ -167,10 +167,11 @@ var EmbarkJS =
EmbarkJS.Storage.get = function(hash) { EmbarkJS.Storage.get = function(hash) {
var self = this; var self = this;
var ipfsHash = this.web3.toAscii(hash); // TODO: detect type, then convert if needed
//var ipfsHash = web3.toAscii(hash);
var promise = new Promise(function(resolve, reject) { var promise = new Promise(function(resolve, reject) {
self.ipfsConnection.object.get([ipfsHash]).then(function(node) { self.ipfsConnection.object.get([hash]).then(function(node) {
resolve(node.data); resolve(node.data);
}); });
}); });
@ -179,10 +180,9 @@ var EmbarkJS =
}; };
EmbarkJS.Storage.getUrl = function(hash) { EmbarkJS.Storage.getUrl = function(hash) {
var self = this; //var ipfsHash = web3.toAscii(hash);
var ipfsHash = web3.toAscii(hash);
return 'http://localhost:8080/ipfs/' + ipfsHash; return 'http://localhost:8080/ipfs/' + hash;
}; };
EmbarkJS.Messages = { EmbarkJS.Messages = {

View File

@ -74,7 +74,7 @@ EmbarkJS.Storage = {
EmbarkJS.Storage.setProvider = function(provider, options) { EmbarkJS.Storage.setProvider = function(provider, options) {
if (provider === 'ipfs') { if (provider === 'ipfs') {
this.currentStorage = EmbarkJS.Storage.IPFS; this.currentStorage = EmbarkJS.Storage.IPFS;
this.ipfsConnection = Ipfs(options.server, options.port); this.ipfsConnection = IpfsApi(options.server, options.port);
} else { } else {
throw Error('unknown provider'); throw Error('unknown provider');
} }
@ -120,10 +120,11 @@ EmbarkJS.Storage.uploadFile = function(inputSelector) {
EmbarkJS.Storage.get = function(hash) { EmbarkJS.Storage.get = function(hash) {
var self = this; var self = this;
var ipfsHash = this.web3.toAscii(hash); // TODO: detect type, then convert if needed
//var ipfsHash = web3.toAscii(hash);
var promise = new Promise(function(resolve, reject) { var promise = new Promise(function(resolve, reject) {
self.ipfsConnection.object.get([ipfsHash]).then(function(node) { self.ipfsConnection.object.get([hash]).then(function(node) {
resolve(node.data); resolve(node.data);
}); });
}); });
@ -132,10 +133,9 @@ EmbarkJS.Storage.get = function(hash) {
}; };
EmbarkJS.Storage.getUrl = function(hash) { EmbarkJS.Storage.getUrl = function(hash) {
var self = this; //var ipfsHash = web3.toAscii(hash);
var ipfsHash = web3.toAscii(hash);
return 'http://localhost:8080/ipfs/' + ipfsHash; return 'http://localhost:8080/ipfs/' + hash;
}; };
EmbarkJS.Messages = { EmbarkJS.Messages = {