@@ -20,29 +20,43 @@ module.exports = (self) => {
20
20
return setImmediate ( ( ) => cb ( new Error ( 'invalid argument' ) ) )
21
21
}
22
22
23
- // TODO remove this and update subsequent code when IPNS is implemented
24
- if ( ! isIpfs . ipfsPath ( name ) ) {
25
- return setImmediate ( ( ) => cb ( new Error ( 'resolve non-IPFS names is not implemented' ) ) )
26
- }
23
+ resolve ( name , opts , cb )
24
+ } )
27
25
28
- const split = name . split ( '/' ) // ['', 'ipfs', 'hash', ...path]
29
- const cid = new CID ( split [ 2 ] )
26
+ function resolve ( name , opts , cb ) {
27
+ if ( isIpfs . ipfsPath ( name ) ) {
28
+ const split = name . split ( '/' ) // ['', 'ipfs', 'hash', ...path]
29
+ const cid = new CID ( split [ 2 ] )
30
30
31
- if ( split . length === 3 ) {
32
- return setImmediate ( ( ) => cb ( null , `/ipfs/${ cidToString ( cid , { base : opts . cidBase } ) } ` ) )
33
- }
31
+ if ( split . length === 3 ) {
32
+ return setImmediate ( ( ) => cb ( null , `/ipfs/${ cidToString ( cid , { base : opts . cidBase } ) } ` ) )
33
+ }
34
34
35
- const path = split . slice ( 3 ) . join ( '/' )
35
+ const path = split . slice ( 3 ) . join ( '/' )
36
36
37
- resolve ( cid , path , ( err , res ) => {
38
- if ( err ) return cb ( err )
39
- const { cid, remainderPath } = res
40
- cb ( null , `/ipfs/${ cidToString ( cid , { base : opts . cidBase } ) } ${ remainderPath ? '/' + remainderPath : '' } ` )
41
- } )
42
- } )
37
+ resolveCID ( cid , path , ( err , res ) => {
38
+ if ( err ) return cb ( err )
39
+ const { cid, remainderPath } = res
40
+ cb ( null , `/ipfs/${ cidToString ( cid , { base : opts . cidBase } ) } ${ remainderPath ? '/' + remainderPath : '' } ` )
41
+ } )
42
+ } else {
43
+ const domain = name . split ( '/' ) [ 2 ]
44
+ const path = name . split ( '/' ) . slice ( 3 ) . join ( '/' )
45
+ console . log ( domain , path )
46
+ return self . dns ( domain , ( err , result ) => {
47
+ if ( err ) return cb ( err )
48
+ const cid = new CID ( result . split ( '/' ) [ 2 ] )
49
+ resolveCID ( cid , path , ( err , res ) => {
50
+ if ( err ) return cb ( err )
51
+ const { cid, remainderPath } = res
52
+ cb ( null , `/ipfs/${ cidToString ( cid , { base : opts . cidBase } ) } ${ remainderPath ? '/' + remainderPath : '' } ` )
53
+ } )
54
+ } )
55
+ }
56
+ }
43
57
44
58
// Resolve the given CID + path to a CID.
45
- function resolve ( cid , path , callback ) {
59
+ function resolveCID ( cid , path , callback ) {
46
60
let value , remainderPath
47
61
doUntil (
48
62
( cb ) => {
0 commit comments