diff --git a/package.json b/package.json index 79cb4e60a9..8ecce948e9 100644 --- a/package.json +++ b/package.json @@ -68,8 +68,8 @@ "fs-blob-store": "^5.2.1", "glob": "^7.0.5", "hapi": "^14.0.0", + "ipfs-api": "ipfs/js-ipfs-api#8cc853f", "ipfs-bitswap": "^0.6.0", - "ipfs-api": "ipfs/js-ipfs-api#91de5ac", "ipfs-block": "^0.3.0", "ipfs-block-service": "^0.4.0", "ipfs-merkle-dag": "^0.6.2", @@ -81,11 +81,11 @@ "joi": "^9.0.4", "libp2p-ipfs": "^0.12.1", "libp2p-ipfs-browser": "^0.12.1", - "lodash.get": "^4.4.0", - "lodash.set": "^4.3.0", + "lodash.get": "^4.4.1", + "lodash.set": "^4.3.1", "mafmt": "^2.1.1", - "multihashes": "^0.2.2", "multiaddr": "^2.0.2", + "multihashes": "^0.2.2", "path-exists": "^3.0.0", "peer-book": "^0.3.0", "peer-id": "^0.7.0", diff --git a/src/core/ipfs/config.js b/src/core/ipfs/config.js index 3996a1bffb..72942bb22e 100644 --- a/src/core/ipfs/config.js +++ b/src/core/ipfs/config.js @@ -1,6 +1,8 @@ 'use strict' const promisify = require('promisify-es6') +const _get = require('lodash.get') +const _set = require('lodash.set') module.exports = function config (self) { return { @@ -22,21 +24,11 @@ module.exports = function config (self) { if (err) { return callback(err) } - const keys = key.split('.') - let finished = false - keys.forEach((key) => { - if (finished) { - return - } - if (config[key]) { - config = config[key] - } else { - finished = true - callback(new Error(('Key does not exist in config'))) - } - }) - if (!finished) { - callback(null, config) + const value = _get(config, key, undefined) + if (!value) { + callback(new Error('Key does not exist in config')) + } else { + callback(null, value) } }) }), @@ -50,33 +42,11 @@ module.exports = function config (self) { } self._repo.config.get((err, config) => { - const configBak = config if (err) { return callback(err) } - const keys = key.split('.') - let finished = false - keys.forEach((key, index) => { - if (finished) { - return - } - if (config[key]) { - if (index === keys.length - 1) { - finished = true - config[key] = value - } - config = config[key] - } else { - if (index === keys.length - 1) { - finished = true - config[key] = value - } else { - config = config[key] = {} - } - } - }) - - self.config.replace(configBak, callback) + _set(config, key, value) + self.config.replace(config, callback) }) }), replace: promisify((config, callback) => {