From aaf127fd1d5074f09984a8118513bafe4d08835a Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sun, 8 Jul 2018 21:28:43 +0300 Subject: [PATCH] move storage config check to the constructor --- lib/modules/ipfs/index.js | 11 ++++------- lib/modules/swarm/index.js | 12 ++++-------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/modules/ipfs/index.js b/lib/modules/ipfs/index.js index f25d156e..77575629 100644 --- a/lib/modules/ipfs/index.js +++ b/lib/modules/ipfs/index.js @@ -17,6 +17,10 @@ class IPFS { this.webServerConfig = embark.config.webServerConfig; this.blockchainConfig = embark.config.blockchainConfig; + if (!this.isIpfsEnabledInTheConfig()) { + return + } + this.setServiceCheck(); this.addProviderToEmbarkJS(); this.addObjectToConsole(); @@ -34,10 +38,6 @@ class IPFS { setServiceCheck() { let self = this; - if (!this.isIpfsEnabledInTheConfig()) { - return - } - self.events.on('check:backOnline:IPFS', function () { self.logger.info(__('IPFS node detected') + '..'); }); @@ -83,9 +83,6 @@ class IPFS { addProviderToEmbarkJS() { const self = this; - if (!this.isIpfsEnabledInTheConfig()) { - return - } self.events.request("version:get:ipfs-api", function(ipfsApiVersion) { let currentIpfsApiVersion = require('../../../package.json').dependencies["ipfs-api"]; diff --git a/lib/modules/swarm/index.js b/lib/modules/swarm/index.js index db91d3cb..46e1a24e 100644 --- a/lib/modules/swarm/index.js +++ b/lib/modules/swarm/index.js @@ -22,6 +22,10 @@ class Swarm { this.getUrl = this.storageConfig.upload.getUrl || this.providerUrl + '/bzz:/'; + if (!this.isSwarmEnabledInTheConfig()) { + return; + } + this.bzz = new Web3Bzz(this.providerUrl); this.setServiceCheck(); @@ -41,10 +45,6 @@ class Swarm { setServiceCheck() { let self = this; - if (!this.isSwarmEnabledInTheConfig()) { - return; - } - this.events.on('check:backOnline:Swarm', function () { self.logger.info(__('Swarm node detected...')); }); @@ -73,10 +73,6 @@ class Swarm { } addProviderToEmbarkJS() { - if (!this.isSwarmEnabledInTheConfig()) { - return; - } - let code = ""; code += "\n" + fs.readFileSync(utils.joinPath(__dirname, 'embarkjs.js')).toString(); code += "\nEmbarkJS.Storage.registerProvider('swarm', __embarkSwarm);";