From d5f77fb965dc2b886cac2dce85af676cc8a3793d Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sun, 8 Jul 2018 21:24:19 +0300 Subject: [PATCH] simplify getJson --- lib/modules/ipfs/index.js | 8 +------- lib/utils/utils.js | 8 ++++++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/modules/ipfs/index.js b/lib/modules/ipfs/index.js index c2edc9fb8..f25d156e2 100644 --- a/lib/modules/ipfs/index.js +++ b/lib/modules/ipfs/index.js @@ -77,14 +77,8 @@ class IPFS { } _checkService(cb) { - const self = this; let url = this._getNodeUrl(); - self.logger.info(`Checking IPFS version on ${url}...`); - if (self.protocol !== 'https'){ - utils.httpGetJson(url, cb); - } else { - utils.httpsGetJson(url, cb); - } + utils.getJson(url, cb); } addProviderToEmbarkJS() { diff --git a/lib/utils/utils.js b/lib/utils/utils.js index 60cb7f0eb..80ddac2b4 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -81,6 +81,13 @@ function httpsGetJson(url, callback) { }); } +function getJson(url, cb) { + if (url.indexOf('https') === 0) { + return httpsGetJson(url, cb); + } + httpGetJson(url, cb); +} + function pingEndpoint(host, port, type, protocol, origin, callback) { const options = { protocolVersion: 13, @@ -363,6 +370,7 @@ module.exports = { httpsGet, httpGetJson, httpsGetJson, + getJson, hexToNumber, pingEndpoint, decodeParams,