From e9fbbd9722c0fb811e81203040c3595c18657931 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Thu, 13 Dec 2018 11:50:36 +0000 Subject: [PATCH] chore: lint cleanup All that is left is TODO comment warnings License: MIT Signed-off-by: Alan Shaw --- src/cli/commands/cat.js | 14 ++-------- src/cli/commands/dns.js | 4 +-- src/cli/commands/get.js | 9 +++---- src/cli/commands/stats/bw.js | 12 +++------ src/core/index.js | 1 + src/core/runtime/dns-browser.js | 13 ++++++--- src/http/api/resources/files-regular.js | 2 +- src/http/index.js | 16 ++++++++--- test/gateway/index.js | 36 ++++++++++++------------- 9 files changed, 53 insertions(+), 54 deletions(-) diff --git a/src/cli/commands/cat.js b/src/cli/commands/cat.js index 3a7548fea0..ec63896ea0 100644 --- a/src/cli/commands/cat.js +++ b/src/cli/commands/cat.js @@ -18,18 +18,8 @@ module.exports = { } }, - handler (argv) { - let path = argv['ipfsPath'] - if (path.indexOf('/ipfs/') !== 1) { - path = path.replace('/ipfs/', '') - } - - const options = { - offset: argv.offset, - length: argv.length - } - - const stream = argv.ipfs.catReadableStream(path, options) + handler ({ ipfs, ipfsPath, offset, length }) { + const stream = ipfs.catReadableStream(ipfsPath, { offset, length }) stream.once('error', (err) => { throw err diff --git a/src/cli/commands/dns.js b/src/cli/commands/dns.js index 5be09d12e1..f1d7270612 100644 --- a/src/cli/commands/dns.js +++ b/src/cli/commands/dns.js @@ -12,8 +12,8 @@ module.exports = { } }, - handler (argv) { - argv.ipfs.dns(argv['domain'], (err, path) => { + handler ({ ipfs, domain }) { + ipfs.dns(domain, (err, path) => { if (err) { throw err } diff --git a/src/cli/commands/get.js b/src/cli/commands/get.js index 1f571e175d..6a787363ed 100644 --- a/src/cli/commands/get.js +++ b/src/cli/commands/get.js @@ -58,12 +58,9 @@ module.exports = { } }, - handler (argv) { - const ipfsPath = argv['ipfsPath'] - - const dir = checkArgs(ipfsPath, argv.output) - - const stream = argv.ipfs.getReadableStream(ipfsPath) + handler ({ ipfs, ipfsPath, output }) { + const dir = checkArgs(ipfsPath, output) + const stream = ipfs.getReadableStream(ipfsPath) stream.once('error', (err) => { if (err) { throw err } diff --git a/src/cli/commands/stats/bw.js b/src/cli/commands/stats/bw.js index 0eb318fe6f..843ed87bb8 100644 --- a/src/cli/commands/stats/bw.js +++ b/src/cli/commands/stats/bw.js @@ -1,6 +1,7 @@ 'use strict' const pull = require('pull-stream') +const print = require('../../utils').print module.exports = { command: 'bw', @@ -26,18 +27,13 @@ module.exports = { } }, - handler (argv) { - const stream = argv.ipfs.stats.bwPullStream({ - peer: argv.peer, - proto: argv.proto, - poll: argv.poll, - interval: argv.interval - }) + handler ({ ipfs, peer, proto, poll, interval }) { + const stream = ipfs.stats.bwPullStream({ peer, proto, poll, interval }) pull( stream, pull.drain((chunk) => { - console.log(`bandwidth status + print(`bandwidth status total in: ${chunk.totalIn}B total out: ${chunk.totalOut}B rate in: ${chunk.rateIn}B/s diff --git a/src/core/index.js b/src/core/index.js index 8aa1fd823c..496396a443 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -127,6 +127,7 @@ class IPFS extends EventEmitter { this._preload = preload(this) this._mfsPreload = mfsPreload(this) this._ipns = undefined + // eslint-disable-next-line no-console this._print = this._options.silent ? this.log : console.log // IPFS Core exposed components diff --git a/src/core/runtime/dns-browser.js b/src/core/runtime/dns-browser.js index a0abb9a4fe..74d0a14cdb 100644 --- a/src/core/runtime/dns-browser.js +++ b/src/core/runtime/dns-browser.js @@ -2,12 +2,19 @@ 'use strict' module.exports = (domain, opts, callback) => { + if (typeof opts === 'function') { + callback = opts + opts = {} + } + + opts = opts || {} + domain = encodeURIComponent(domain) let url = `https://ipfs.io/api/v0/dns?arg=${domain}` - for (const prop in opts) { - url += `&${prop}=${opts[prop]}` - } + Object.keys(opts).forEach(prop => { + url += `&${encodeURIComponent(prop)}=${encodeURIComponent(opts[prop])}` + }) self.fetch(url, { mode: 'cors' }) .then((response) => { diff --git a/src/http/api/resources/files-regular.js b/src/http/api/resources/files-regular.js index c8fae5112f..577d8b561c 100644 --- a/src/http/api/resources/files-regular.js +++ b/src/http/api/resources/files-regular.js @@ -235,7 +235,7 @@ exports.add = { rawLeaves: request.query['raw-leaves'], progress: request.query.progress ? progressHandler : null, onlyHash: request.query['only-hash'], - hashAlg: request.query['hash'], + hashAlg: request.query.hash, wrapWithDirectory: request.query['wrap-with-directory'], pin: request.query.pin, chunker: request.query.chunker diff --git a/src/http/index.js b/src/http/index.js index fbace44d3b..e80c6b609f 100644 --- a/src/http/index.js +++ b/src/http/index.js @@ -53,12 +53,20 @@ function HttpApi (repo, config, cliArgs) { // Attempt to use any of the WebRTC versions available globally let electronWebRTC let wrtc - try { electronWebRTC = require('electron-webrtc')() } catch (err) {} - try { wrtc = require('wrtc') } catch (err) {} + try { + electronWebRTC = require('electron-webrtc')() + } catch (err) { + this.log('failed to load optional electron-webrtc dependency') + } + try { + wrtc = require('wrtc') + } catch (err) { + this.log('failed to load optional webrtc dependency') + } if (wrtc || electronWebRTC) { const using = wrtc ? 'wrtc' : 'electron-webrtc' - console.log(`Using ${using} for webrtc support`) + this.log(`Using ${using} for webrtc support`) const wstar = new WStar({ wrtc: (wrtc || electronWebRTC) }) libp2p.modules.transport = [TCP, WS, wstar] libp2p.modules.peerDiscovery = [MulticastDNS, Bootstrap, wstar.discovery] @@ -179,7 +187,7 @@ function HttpApi (repo, config, cliArgs) { ], (err) => { if (err) { this.log.error(err) - console.log('There were errors stopping') + console.error('There were errors stopping') } callback() }) diff --git a/test/gateway/index.js b/test/gateway/index.js index 952b0d3a82..682c4497b4 100644 --- a/test/gateway/index.js +++ b/test/gateway/index.js @@ -145,9 +145,9 @@ describe('HTTP Gateway', function () { expect(res.statusCode).to.equal(400) expect(res.result.Message).to.be.a('string') expect(res.headers['cache-control']).to.equal('no-cache') - expect(res.headers['etag']).to.equal(undefined) + expect(res.headers.etag).to.equal(undefined) expect(res.headers['x-ipfs-path']).to.equal(undefined) - expect(res.headers['suborigin']).to.equal(undefined) + expect(res.headers.suborigin).to.equal(undefined) done() }) }) @@ -160,9 +160,9 @@ describe('HTTP Gateway', function () { expect(res.statusCode).to.equal(400) expect(res.result.Message).to.be.a('string') expect(res.headers['cache-control']).to.equal('no-cache') - expect(res.headers['etag']).to.equal(undefined) + expect(res.headers.etag).to.equal(undefined) expect(res.headers['x-ipfs-path']).to.equal(undefined) - expect(res.headers['suborigin']).to.equal(undefined) + expect(res.headers.suborigin).to.equal(undefined) done() }) }) @@ -176,9 +176,9 @@ describe('HTTP Gateway', function () { expect(res.rawPayload).to.eql(Buffer.from('hello world' + '\n')) expect(res.payload).to.equal('hello world' + '\n') expect(res.headers['cache-control']).to.equal('public, max-age=29030400, immutable') - expect(res.headers['etag']).to.equal('"QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o"') + expect(res.headers.etag).to.equal('"QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o"') expect(res.headers['x-ipfs-path']).to.equal('/ipfs/QmT78zSuBmuS4z925WZfrqQ1qHaJ56DQaTfyMUF7F8ff5o') - expect(res.headers['suborigin']).to.equal('ipfs000bafybeicg2rebjoofv4kbyovkw7af3rpiitvnl6i7ckcywaq6xjcxnc2mby') + expect(res.headers.suborigin).to.equal('ipfs000bafybeicg2rebjoofv4kbyovkw7af3rpiitvnl6i7ckcywaq6xjcxnc2mby') done() }) @@ -193,9 +193,9 @@ describe('HTTP Gateway', function () { expect(res.statusCode).to.equal(200) expect(res.rawPayload).to.eql(Buffer.from('hello world' + '\n')) expect(res.payload).to.equal('hello world' + '\n') - expect(res.headers['etag']).to.equal(TO-DO) + expect(res.headers.etag).to.equal(TO-DO) expect(res.headers['x-ipfs-path']).to.equal(TO-DO) - expect(res.headers['suborigin']).to.equal(TO-DO) + expect(res.headers.suborigin).to.equal(TO-DO) expect(res.headers['cache-control']).to.equal('public, max-age=29030400, immutable') done() @@ -227,8 +227,8 @@ describe('HTTP Gateway', function () { expect(res.headers['content-type']).to.equal('image/jpeg') expect(res.headers['x-ipfs-path']).to.equal('/ipfs/' + kitty) expect(res.headers['cache-control']).to.equal('public, max-age=29030400, immutable') - expect(res.headers['etag']).to.equal('"Qmd286K6pohQcTKYqnS1YhWrCiS4gz7Xi34sdwMe9USZ7u"') - expect(res.headers['suborigin']).to.equal('ipfs000bafybeidsg6t7ici2osxjkukisd5inixiunqdpq2q5jy4a2ruzdf6ewsqk4') + expect(res.headers.etag).to.equal('"Qmd286K6pohQcTKYqnS1YhWrCiS4gz7Xi34sdwMe9USZ7u"') + expect(res.headers.suborigin).to.equal('ipfs000bafybeidsg6t7ici2osxjkukisd5inixiunqdpq2q5jy4a2ruzdf6ewsqk4') let fileSignature = fileType(res.rawPayload) expect(fileSignature.mime).to.equal('image/jpeg') @@ -277,8 +277,8 @@ describe('HTTP Gateway', function () { expect(res.headers['content-type']).to.equal('text/html; charset=utf-8') expect(res.headers['x-ipfs-path']).to.equal('/ipfs/' + dir) expect(res.headers['cache-control']).to.equal('no-cache') - expect(res.headers['etag']).to.equal(undefined) - expect(res.headers['suborigin']).to.equal('ipfs000bafybeidsg6t7ici2osxjkukisd5inixiunqdpq2q5jy4a2ruzdf6ewsqk4') + expect(res.headers.etag).to.equal(undefined) + expect(res.headers.suborigin).to.equal('ipfs000bafybeidsg6t7ici2osxjkukisd5inixiunqdpq2q5jy4a2ruzdf6ewsqk4') // check if the cat picture is in the payload as a way to check // if this is an index of this directory @@ -299,8 +299,8 @@ describe('HTTP Gateway', function () { expect(res.headers['content-type']).to.equal('text/html; charset=utf-8') expect(res.headers['x-ipfs-path']).to.equal('/ipfs/' + dir) expect(res.headers['cache-control']).to.equal('public, max-age=29030400, immutable') - expect(res.headers['etag']).to.equal('"Qma6665X5k3zti8nKy7gmXK2BndNDSkgmANpV6k3FUjUeg"') - expect(res.headers['suborigin']).to.equal('ipfs000bafybeigccfheqv7upr4k64bkg5b5wiwelunyn2l2rbirmm43m34lcpuqqe') + expect(res.headers.etag).to.equal('"Qma6665X5k3zti8nKy7gmXK2BndNDSkgmANpV6k3FUjUeg"') + expect(res.headers.suborigin).to.equal('ipfs000bafybeigccfheqv7upr4k64bkg5b5wiwelunyn2l2rbirmm43m34lcpuqqe') expect(res.rawPayload).to.deep.equal(directoryContent['index.html']) done() }) @@ -317,8 +317,8 @@ describe('HTTP Gateway', function () { expect(res.headers['content-type']).to.equal('text/html; charset=utf-8') expect(res.headers['x-ipfs-path']).to.equal('/ipfs/' + dir) expect(res.headers['cache-control']).to.equal('public, max-age=29030400, immutable') - expect(res.headers['etag']).to.equal('"QmUBKGqJWiJYMrNed4bKsbo1nGYGmY418WCc2HgcwRvmHc"') - expect(res.headers['suborigin']).to.equal('ipfs000bafybeigccfheqv7upr4k64bkg5b5wiwelunyn2l2rbirmm43m34lcpuqqe') + expect(res.headers.etag).to.equal('"QmUBKGqJWiJYMrNed4bKsbo1nGYGmY418WCc2HgcwRvmHc"') + expect(res.headers.suborigin).to.equal('ipfs000bafybeigccfheqv7upr4k64bkg5b5wiwelunyn2l2rbirmm43m34lcpuqqe') expect(res.rawPayload).to.deep.equal(directoryContent['nested-folder/nested.html']) done() }) @@ -332,7 +332,7 @@ describe('HTTP Gateway', function () { url: '/ipfs/' + dir }, (res) => { expect(res.statusCode).to.equal(301) - expect(res.headers['location']).to.equal('/ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/') + expect(res.headers.location).to.equal('/ipfs/QmW2WQi7j6c7UgJTarActp7tDNikE4B2qXtFCfLPdsgaTQ/') expect(res.headers['x-ipfs-path']).to.equal(undefined) done() }) @@ -346,7 +346,7 @@ describe('HTTP Gateway', function () { url: '/ipfs/' + dir }, (res) => { expect(res.statusCode).to.equal(302) - expect(res.headers['location']).to.equal('/ipfs/QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/index.html') + expect(res.headers.location).to.equal('/ipfs/QmbQD7EMEL1zeebwBsWEfA3ndgSS6F7S6iTuwuqasPgVRi/index.html') expect(res.headers['x-ipfs-path']).to.equal(undefined) done() })