diff --git a/js/build/embark.bundle.js b/js/build/embark.bundle.js index 321bfd244..120b40b6f 100644 --- a/js/build/embark.bundle.js +++ b/js/build/embark.bundle.js @@ -156,13 +156,16 @@ var EmbarkJS = EmbarkJS.Storage = { }; - // EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'}) - //{server: ‘localhost’, port: ‘5001’}; + // EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'}) EmbarkJS.Storage.setProvider = function(provider, options) { if (provider === 'ipfs') { this.currentStorage = EmbarkJS.Storage.IPFS; - this.ipfsConnection = IpfsApi(options.server, options.port); + if (options === undefined) { + this.ipfsConnection = IpfsApi('localhost', '5001'); + } else { + this.ipfsConnection = IpfsApi(options.server, options.port); + } } else { throw Error('unknown provider'); } @@ -170,6 +173,9 @@ var EmbarkJS = EmbarkJS.Storage.saveText = function(text) { var self = this; + if (!this.ipfsConnection) { + this.setProvider('ipfs'); + } var promise = new Promise(function(resolve, reject) { self.ipfsConnection.add((new self.ipfsConnection.Buffer(text)), function(err, result) { if (err) { @@ -191,6 +197,10 @@ var EmbarkJS = throw new Error('no file found'); } + if (!this.ipfsConnection) { + this.setProvider('ipfs'); + } + var promise = new Promise(function(resolve, reject) { var reader = new FileReader(); reader.onloadend = function() { @@ -214,6 +224,9 @@ var EmbarkJS = var self = this; // TODO: detect type, then convert if needed //var ipfsHash = web3.toAscii(hash); + if (!this.ipfsConnection) { + this.setProvider('ipfs'); + } var promise = new Promise(function(resolve, reject) { self.ipfsConnection.object.get([hash]).then(function(node) { diff --git a/js/embark.js b/js/embark.js index 903e35b74..be6831c05 100644 --- a/js/embark.js +++ b/js/embark.js @@ -109,13 +109,16 @@ EmbarkJS.IPFS = 'ipfs'; EmbarkJS.Storage = { }; -// EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'}) -//{server: ‘localhost’, port: ‘5001’}; +// EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'}) EmbarkJS.Storage.setProvider = function(provider, options) { if (provider === 'ipfs') { this.currentStorage = EmbarkJS.Storage.IPFS; - this.ipfsConnection = IpfsApi(options.server, options.port); + if (options === undefined) { + this.ipfsConnection = IpfsApi('localhost', '5001'); + } else { + this.ipfsConnection = IpfsApi(options.server, options.port); + } } else { throw Error('unknown provider'); } @@ -123,6 +126,9 @@ EmbarkJS.Storage.setProvider = function(provider, options) { EmbarkJS.Storage.saveText = function(text) { var self = this; + if (!this.ipfsConnection) { + this.setProvider('ipfs'); + } var promise = new Promise(function(resolve, reject) { self.ipfsConnection.add((new self.ipfsConnection.Buffer(text)), function(err, result) { if (err) { @@ -144,6 +150,10 @@ EmbarkJS.Storage.uploadFile = function(inputSelector) { throw new Error('no file found'); } + if (!this.ipfsConnection) { + this.setProvider('ipfs'); + } + var promise = new Promise(function(resolve, reject) { var reader = new FileReader(); reader.onloadend = function() { @@ -167,6 +177,9 @@ EmbarkJS.Storage.get = function(hash) { var self = this; // TODO: detect type, then convert if needed //var ipfsHash = web3.toAscii(hash); + if (!this.ipfsConnection) { + this.setProvider('ipfs'); + } var promise = new Promise(function(resolve, reject) { self.ipfsConnection.object.get([hash]).then(function(node) {