refactor storage config check

This commit is contained in:
Iuri Matias 2018-07-08 21:14:44 +03:00
parent 46a6d391cd
commit 97be8b7463
2 changed files with 16 additions and 30 deletions

View File

@ -2,7 +2,6 @@ const UploadIPFS = require('./upload.js');
const utils = require('../../utils/utils.js'); const utils = require('../../utils/utils.js');
const fs = require('../../core/fs.js'); const fs = require('../../core/fs.js');
const IpfsApi = require('ipfs-api'); const IpfsApi = require('ipfs-api');
const _ = require('underscore');
const StorageProcessesLauncher = require('../../processes/storageProcesses/storageProcessesLauncher'); const StorageProcessesLauncher = require('../../processes/storageProcesses/storageProcessesLauncher');
class IPFS { class IPFS {
@ -35,14 +34,8 @@ class IPFS {
setServiceCheck() { setServiceCheck() {
let self = this; let self = this;
let storageConfig = this.storageConfig; if (!this.isIpfsEnabledInTheConfig()) {
return
if (!storageConfig.enabled) {
return;
}
if (_.findWhere(this.storageConfig.dappConnection, {'provider': 'ipfs'}) === undefined && (storageConfig.upload.provider !== 'ipfs' || storageConfig.available_providers.indexOf("ipfs") < 0)) {
return;
} }
self.events.on('check:backOnline:IPFS', function () { self.events.on('check:backOnline:IPFS', function () {
@ -96,13 +89,8 @@ class IPFS {
addProviderToEmbarkJS() { addProviderToEmbarkJS() {
const self = this; const self = this;
// TODO: make this a shouldAdd condition if (!this.isIpfsEnabledInTheConfig()) {
if (this.storageConfig === {}) { return
return;
}
if (this.storageConfig.available_providers.indexOf('ipfs') < 0 || _.findWhere(this.storageConfig.dappConnection, {'provider': 'ipfs'}) === undefined || this.storageConfig.enabled !== true) {
return;
} }
self.events.request("version:get:ipfs-api", function(ipfsApiVersion) { self.events.request("version:get:ipfs-api", function(ipfsApiVersion) {
@ -152,6 +140,11 @@ class IPFS {
}); });
} }
isIpfsEnabledInTheConfig() {
let { enabled, available_providers, dappConnection } = this.storageConfig;
return enabled && (available_providers.indexOf('ipfs') > 0 || dappConnection.find(c => c.provider === 'ipfs'));
}
} }
module.exports = IPFS; module.exports = IPFS;

View File

@ -2,7 +2,6 @@ const UploadSwarm = require('./upload.js');
const utils = require('../../utils/utils.js'); const utils = require('../../utils/utils.js');
const fs = require('../../core/fs.js'); const fs = require('../../core/fs.js');
const Web3Bzz = require('web3-bzz'); const Web3Bzz = require('web3-bzz');
const _ = require('underscore');
const StorageProcessesLauncher = require('../../processes/storageProcesses/storageProcessesLauncher'); const StorageProcessesLauncher = require('../../processes/storageProcesses/storageProcessesLauncher');
class Swarm { class Swarm {
@ -42,12 +41,7 @@ class Swarm {
setServiceCheck() { setServiceCheck() {
let self = this; let self = this;
let storageConfig = this.storageConfig; if (!this.isSwarmEnabledInTheConfig()) {
if (!storageConfig.enabled) {
return;
}
if (_.findWhere(this.storageConfig.dappConnection, {'provider': 'swarm'}) === undefined && (storageConfig.upload.provider !== 'swarm' || storageConfig.available_providers.indexOf("swarm") < 0)) {
return; return;
} }
@ -79,12 +73,7 @@ class Swarm {
} }
addProviderToEmbarkJS() { addProviderToEmbarkJS() {
// TODO: make this a shouldAdd condition if (!this.isSwarmEnabledInTheConfig()) {
if (this.storageConfig === {}) {
return;
}
if (this.storageConfig.available_providers.indexOf('swarm') < 0 || _.findWhere(this.storageConfig.dappConnection, {'provider': 'swarm'}) === undefined || this.storageConfig.enabled !== true) {
return; return;
} }
@ -122,7 +111,11 @@ class Swarm {
}); });
} }
isSwarmEnabledInTheConfig() {
let { enabled, available_providers, dappConnection } = this.storageConfig;
return enabled && (available_providers.indexOf('swarm') > 0 || dappConnection.find(c => c.provider === 'swarm'));
}
} }
module.exports = Swarm; module.exports = Swarm;