From c70e583557ee84860f10631dc62278e9bc9d60c0 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sat, 7 Jul 2018 21:56:37 +0300 Subject: [PATCH] get correct ipfs node depending on the config --- lib/modules/ipfs/index.js | 19 +++++++++++++++---- lib/modules/storage/index.js | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/modules/ipfs/index.js b/lib/modules/ipfs/index.js index 9a47723e..1d9a3741 100644 --- a/lib/modules/ipfs/index.js +++ b/lib/modules/ipfs/index.js @@ -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); diff --git a/lib/modules/storage/index.js b/lib/modules/storage/index.js index 5631c203..9d654c71 100644 --- a/lib/modules/storage/index.js +++ b/lib/modules/storage/index.js @@ -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