diff --git a/lib/modules/storage/index.js b/lib/modules/storage/index.js index 3327524f..9f8162a9 100644 --- a/lib/modules/storage/index.js +++ b/lib/modules/storage/index.js @@ -155,59 +155,45 @@ class Storage { this._embark.addProviderInit('storage', code, shouldInit); } + checkStorageService(platform, url, callback) { + const self = this; + const errorObj = {message: __('Cannot upload: {{platform}} node is not running on {{url}}.', {platform: platform, url: url})}; + + // start the upload storage node + self._checkStorageEndpoint(platform, function (err) { + if (!err) { + return callback(); + } + self._startStorageNode(platform, (err) => { + if (err) { + self._logger.error(err); + return callback(errorObj); + } + // Check endpoint again to see if really did start + self._checkStorageEndpoint(platform, (err) => { + if (err) { + return callback(errorObj); + } + callback(); + }); + }); + }); + } + startStorageProcesses(){ let platform = this._storageConfig.upload.provider; let self = this; async.waterfall([ - function checkStorageService(callback){ - const errorObj = {message: __('Cannot upload: {{platform}} node is not running on {{url}}.', {platform: platform, url: utils.buildUrlFromConfig(self._storageConfig.upload)})}; - - // start the upload storage node - self._checkStorageEndpoint(platform, function (err) { - if (!err) { - return callback(); - } - self._startStorageNode(platform, (err) => { - if (err) { - self._logger.error(err); - return callback(errorObj); - } - // Check endpoint again to see if really did start - self._checkStorageEndpoint(platform, (err) => { - if (err) { - return callback(errorObj); - } - callback(); - }); - }); - }); + function _checkStorageService(callback){ + self.checkStorageService(platform, utils.buildUrlFromConfig(self._storageConfig.upload), callback); }, function checkDappConnectionStorageService(callback){ // start any dappConnection storage nodes self._validDappProviders.forEach(dappConn => { if(!dappConn.provider || dappConn.provider === platform) return; // don't start the process we've just started above - - const errorObj = {message: __('Cannot start {{platform}} node on {{url}}.', {platform: dappConn.provider, url: utils.buildUrlFromConfig(dappConn)})}; - - self._checkStorageEndpoint(dappConn.provider, function (err) { - if (!err) { - return callback(); - } - self._startStorageNode(dappConn.provider, (err) => { - if (err) { - self._logger.error(err); - return callback(errorObj); - } - // Check endpoint again to see if really did start - self._checkStorageEndpoint(dappConn.provider, (err) => { - if (err) { - return callback(errorObj); - } - callback(); - }); - }); - }); + + self.checkStorageService(dappConn.provider, utils.buildUrlFromConfig(dappConn), callback); }); } ]); diff --git a/test_apps/test_app/config/storage.json b/test_apps/test_app/config/storage.json index 13912156..2209629d 100644 --- a/test_apps/test_app/config/storage.json +++ b/test_apps/test_app/config/storage.json @@ -36,4 +36,4 @@ "getUrl": "https://ipfs.infura.io/ipfs/" } } -} \ No newline at end of file +}