get correct ipfs node depending on the config

This commit is contained in:
Iuri Matias 2018-07-07 21:56:37 +03:00
parent 8720f43e39
commit c70e583557
2 changed files with 16 additions and 4 deletions

View File

@ -13,9 +13,6 @@ class IPFS {
this.events = embark.events;
this.buildDir = options.buildDir;
this.storageConfig = embark.config.storageConfig;
this.host = options.host || this.storageConfig.upload.host;
this.port = options.port || this.storageConfig.upload.port;
this.protocol = options.protocol || this.storageConfig.upload.protocol;
this.embark = embark;
this.webServerConfig = embark.config.webServerConfig
@ -83,9 +80,23 @@ class IPFS {
});
}
_getNodeUrl() {
if (this.storageConfig.upload.provider === 'ipfs') {
let { protocol, host, port } = this.storageConfig.upload.provider;
return (protocol || 'http') + '://' + host + ':' + port + '/api/v0/version';
}
for (let connection of this.storageConfig.dappConnection) {
if (connection.provider === 'ipfs') {
let { protocol, host, port } = connection;
return (protocol || 'http') + '://' + host + ':' + port + '/api/v0/version';
}
}
}
_checkService(cb) {
const self = this;
let url = (self.protocol || 'http') + '://' + self.host + ':' + self.port + '/api/v0/version';
let url = this._getNodeUrl();
self.logger.info(`Checking IPFS version on ${url}...`);
if (self.protocol !== 'https'){
utils.httpGetJson(url, cb);

View File

@ -31,6 +31,7 @@ class Storage {
* @returns {void}
*/
addSetProviders() {
const self = this;
// filter list of dapp connections based on available_providers set in config
let hasSwarm = _.contains(this.storageConfig.available_providers, 'swarm'); // don't need to eval this in every loop iteration
// contains valid dapp storage providers