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

Commit af678ae

Browse files
author
Alan Shaw
committed
fix: many fixes
1 parent fadff95 commit af678ae

File tree

7 files changed

+39
-60
lines changed

7 files changed

+39
-60
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
"libp2p-delegated-content-routing": "^0.4.1",
140140
"libp2p-delegated-peer-routing": "^0.4.0",
141141
"libp2p-floodsub": "^0.20.0",
142-
"libp2p-gossipsub": "^0.2.0",
142+
"libp2p-gossipsub": "github:ChainSafe/gossipsub-js#fix/bind-is-not-needed",
143143
"libp2p-kad-dht": "^0.18.3",
144144
"libp2p-keychain": "^0.6.0",
145145
"libp2p-mdns": "^0.13.0",

src/cli/commands/ls.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,21 @@ module.exports = {
5555
const ipfs = await getIpfs()
5656
let first = true
5757

58-
const widths = {
59-
cid: 0,
60-
size: 0,
61-
mtime: 0,
62-
mode: 0
58+
let maxWidths = []
59+
const getMaxWidths = (...args) => {
60+
maxWidths = args.map((v, i) => Math.max(maxWidths[i] || 0, v.length))
61+
return maxWidths
6362
}
6463

6564
const printLink = (mode, mtime, cid, size, name, depth = 0) => {
65+
const widths = getMaxWidths(mode, mtime, cid, size, name)
6666
// todo: fix this by resolving https://github.com/ipfs/js-ipfs-unixfs-exporter/issues/24
6767
const padding = Math.max(depth - pathParts.length, 0)
6868
print(
69-
rightpad(mode, 11) +
70-
rightpad(mtime || '-', widths.mtime + 1) +
71-
rightpad(cid, widths.cid + 1) +
72-
rightpad(size || '-', widths.size + 1) +
69+
rightpad(mode, widths[0] + 1) +
70+
rightpad(mtime, widths[1] + 1) +
71+
rightpad(cid, widths[2] + 1) +
72+
rightpad(size, widths[3] + 1) +
7373
' '.repeat(padding) + name
7474
)
7575
}
@@ -78,25 +78,19 @@ module.exports = {
7878
const mode = formatMode(link.mode, link.type === 'dir')
7979
const mtime = formatMtime(link.mtime)
8080
const cid = cidToString(link.cid, { base: cidBase })
81+
const size = link.size ? String(link.size) : '-'
8182
const name = link.type === 'dir' ? `${link.name || ''}/` : link.name
8283

83-
widths.mode = Math.max(widths.mode, mode)
84-
widths.mtime = Math.max(widths.mtime, mtime)
85-
widths.cid = Math.max(widths.cid, cid.length)
86-
widths.size = Math.max(widths.size, String(link.size).length)
87-
8884
if (first) {
8985
first = false
9086
if (headers) {
91-
widths.mode = Math.max(widths.mode, 'Mode'.length)
92-
widths.mtime = Math.max(widths.mtime, 'Mtime'.length)
93-
widths.cid = Math.max(widths.cid, 'Hash'.length)
94-
widths.size = Math.max(widths.size, 'Size'.length)
87+
// Seed max widths for the first item
88+
getMaxWidths(mode, mtime, cid, size, name)
9589
printLink('Mode', 'Mtime', 'Hash', 'Size', 'Name')
9690
}
9791
}
9892

99-
printLink(mode, mtime, cid, link.size, name, link.depth)
93+
printLink(mode, mtime, cid, size, name, link.depth)
10094
}
10195
})())
10296
}

src/core/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ const mapFile = (file, options) => {
158158
output.type = 'file'
159159

160160
if (options.includeContent) {
161-
output.content = file.content
161+
output.content = file.content()
162162
}
163163
}
164164

src/http/api/resources/files-regular.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,31 +107,29 @@ exports.get = {
107107
async handler (request, h) {
108108
const { ipfs } = request.server.app
109109
const { key } = request.pre.args
110-
const pack = tar.pack()
111-
112-
let filesArray
113-
try {
114-
filesArray = await all(ipfs.get(key))
115-
} catch (err) {
116-
throw Boom.boomify(err, { message: 'Failed to get key' })
117-
}
118110

111+
const pack = tar.pack()
119112
pack.entry = promisify(pack.entry.bind(pack))
120113

121-
Promise
122-
.all(filesArray.map(async file => {
123-
if (!file.content) {
124-
return pack.entry({ name: file.path, type: 'directory' })
114+
const streamFiles = async () => {
115+
try {
116+
for await (const file of ipfs.get(key)) {
117+
if (file.content) {
118+
const content = await concat(file.content)
119+
pack.entry({ name: file.path, size: file.size }, content.slice())
120+
} else {
121+
pack.entry({ name: file.path, type: 'directory' })
122+
}
125123
}
126-
const content = await concat(file.content)
127-
return pack.entry({ name: file.path, size: file.size }, content.slice())
128-
}))
129-
.then(() => pack.finalize())
130-
.catch(err => {
124+
pack.finalize()
125+
} catch (err) {
131126
log.error(err)
132127
pack.emit('error', err)
133128
pack.destroy()
134-
})
129+
}
130+
}
131+
132+
streamFiles()
135133

136134
// reply must be called right away so that tar-stream offloads its content
137135
// otherwise it will block in large files

src/http/api/resources/swarm.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,11 @@ exports.addrs = {
5555
const { ipfs } = request.server.app
5656
const peers = await ipfs.swarm.addrs()
5757

58-
const addrs = {}
59-
peers.forEach((peer) => {
60-
addrs[peer.id.toString()] = peer.multiaddrs.toArray()
61-
.map((addr) => addr.toString())
62-
})
63-
6458
return h.response({
65-
Addrs: addrs
59+
Addrs: peers.reduce((addrs, peer) => {
60+
addrs[peer.id.toString()] = peer.addrs.map(a => a.toString())
61+
return addrs
62+
}, {})
6663
})
6764
}
6865
}

test/core/interface.spec.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const tests = require('interface-ipfs-core')
55
const merge = require('merge-options')
66
const { createFactory } = require('ipfsd-ctl')
7+
const { isNode } = require('ipfs-utils/src/env')
78
const IPFS = require('../../src')
89

910
/** @typedef { import("ipfsd-ctl").ControllerOptions } ControllerOptions */
@@ -33,13 +34,7 @@ describe('interface-ipfs-core tests', function () {
3334
const commonFactory = createFactory(commonOptions, overrides)
3435

3536
tests.root(commonFactory, {
36-
skip: isNode ? [{
37-
name: 'should ignore a directory from the file system',
38-
reason: 'FIXME: unixfs importer returns an extra QmUNLLs dir first (seems to be fixed in 0.42)'
39-
}] : [{
40-
name: 'should ignore a directory from the file system',
41-
reason: 'FIXME: unixfs importer returns an extra QmUNLLs dir first (seems to be fixed in 0.42)'
42-
}, {
37+
skip: isNode ? null : [{
4338
name: 'should add with mtime as hrtime',
4439
reason: 'Not designed to run in the browser'
4540
}]

test/http-api/interface.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@ describe('interface-ipfs-core over ipfs-http-client tests', function () {
3333
}
3434
const commonFactory = createFactory(commonOptions, overrides)
3535

36-
tests.root(commonFactory, {
37-
skip: [{
38-
name: 'should ignore a directory from the file system',
39-
reason: 'FIXME: unixfs importer returns an extra QmUNLLs dir first (seems to be fixed in 0.42)'
40-
}]
41-
})
36+
tests.root(commonFactory)
4237

4338
tests.bitswap(commonFactory)
4439

@@ -113,5 +108,5 @@ describe('interface-ipfs-core over ipfs-http-client tests', function () {
113108

114109
tests.stats(commonFactory)
115110

116-
tests.swarm(commonFactory, { skip: true })
111+
tests.swarm(commonFactory)
117112
})

0 commit comments

Comments
 (0)