1
1
'use strict'
2
2
3
3
const { print, rightpad} = require ( '../utils' )
4
+ const Unixfs = require ( 'ipfs-unixfs' )
4
5
5
6
module . exports = {
6
7
command : 'ls' ,
@@ -15,39 +16,31 @@ module.exports = {
15
16
default : false
16
17
} ,
17
18
'resolve-type' : {
18
- desc : 'Resolve linked objects to find out their types.' ,
19
+ desc : 'Resolve linked objects to find out their types. (not implemented yet) ' ,
19
20
type : 'boolean' ,
20
- default : false // TODO: should be true, false for now, as not implemented
21
+ default : false // should be true when implemented
21
22
}
22
23
} ,
23
24
24
25
handler ( argv ) {
25
- // TODO: should probably be refactored into a src/core/components/ls.js, and also exposed via the HTTP-API?
26
26
console . log ( argv . _ . length )
27
27
if ( argv . _ . length !== 2 ) {
28
- // TODO
29
- throw new Error ( 'TODO not implemented yet: no arg => read from stdin, several args ls all of them, with header for each' )
28
+ throw new Error ( 'Other arguments than single hash not implemented yet.' )
30
29
}
31
30
32
31
argv . ipfs . object . get ( argv . _ [ 1 ] , { enc : 'base58' } , ( err , node ) => {
33
32
if ( err ) {
34
- // TODO resolve path, to handle addresse like
35
- // QmTkzDwWqPbnAh5YiV5VwcTLnGdwSNsNTn2aDxdXBFca7D/lib
36
- // /ipfs/QmTkzDwWqPbnAh5YiV5VwcTLnGdwSNsNTn2aDxdXBFca7D
37
- // (both fails in js-ipfs, works in go-ipfs)
38
33
throw err
39
34
}
40
35
let { data, links} = node . toJSON ( )
41
36
42
- // TODO: proper way to check type (via unixfs?), not hardcoded here
43
- if ( ! data || data . length !== 2 ||
44
- data [ 0 ] !== 8 || // ??? some multicodec id, or ? find out
45
- data [ 1 ] !== 1 ) { // unixfs directory type
37
+ const fileDesc = Unixfs . unmarshal ( data )
38
+ if ( fileDesc . type !== 'directory' ) {
46
39
throw new Error ( 'merkeldag node was not a directory' ) // TODO: support shards
47
40
}
48
41
49
42
if ( argv [ 'resolve-type' ] ) {
50
- throw new Error ( '--resolve-type not implemented yet' ) // TODO
43
+ throw new Error ( '--resolve-type not implemented yet' )
51
44
}
52
45
53
46
if ( argv . headers ) {
0 commit comments