refactor storage config check

This commit is contained in:
Iuri Matias 2018-07-08 21:14:44 +03:00
parent 700b2199bd
commit 768138c5b6
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 fs = require('../../core/fs.js');
const IpfsApi = require('ipfs-api');
const _ = require('underscore');
const StorageProcessesLauncher = require('../../processes/storageProcesses/storageProcessesLauncher');
class IPFS {
@ -35,14 +34,8 @@ class IPFS {
setServiceCheck() {
let self = this;
let storageConfig = this.storageConfig;
if (!storageConfig.enabled) {
return;
}
if (_.findWhere(this.storageConfig.dappConnection, {'provider': 'ipfs'}) === undefined && (storageConfig.upload.provider !== 'ipfs' || storageConfig.available_providers.indexOf("ipfs") < 0)) {
return;
if (!this.isIpfsEnabledInTheConfig()) {
return
}
self.events.on('check:backOnline:IPFS', function () {
@ -96,13 +89,8 @@ class IPFS {
addProviderToEmbarkJS() {
const self = this;
// TODO: make this a shouldAdd condition
if (this.storageConfig === {}) {
return;
}
if (this.storageConfig.available_providers.indexOf('ipfs') < 0 || _.findWhere(this.storageConfig.dappConnection, {'provider': 'ipfs'}) === undefined || this.storageConfig.enabled !== true) {
return;
if (!this.isIpfsEnabledInTheConfig()) {
return
}
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;

View File

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