Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

chore: lint cleanup #1779

Merged
merged 1 commit into from
Dec 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/cli/commands/cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 3 additions & 6 deletions src/cli/commands/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
12 changes: 4 additions & 8 deletions src/cli/commands/stats/bw.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const pull = require('pull-stream')
const print = require('../../utils').print

module.exports = {
command: 'bw',
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/core/runtime/dns-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/http/api/resources/files-regular.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions src/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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()
})
Expand Down
36 changes: 18 additions & 18 deletions test/gateway/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand All @@ -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()
})
})
Expand All @@ -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()
})
Expand All @@ -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()
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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()
})
Expand All @@ -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()
})
Expand All @@ -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()
})
Expand All @@ -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()
})
Expand Down