refactor storage module
This commit is contained in:
parent
eadbeb0498
commit
60c687aa41
|
@ -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);
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
|
|
@ -36,4 +36,4 @@
|
|||
"getUrl": "https://ipfs.infura.io/ipfs/"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue