33const promisify = require ( 'promisify-es6' )
44const dagPB = require ( 'ipld-dag-pb' )
55const DAGLink = dagPB . DAGLink
6- const cleanMultihash = require ( '../utils/clean-multihash ' )
6+ const CID = require ( 'cids ' )
77const LRU = require ( 'lru-cache' )
88const lruOptions = {
99 max : 128
@@ -12,7 +12,7 @@ const lruOptions = {
1212const cache = new LRU ( lruOptions )
1313
1414module . exports = ( send ) => {
15- return promisify ( ( multihash , options , callback ) => {
15+ return promisify ( ( cid , options , callback ) => {
1616 if ( typeof options === 'function' ) {
1717 callback = options
1818 options = { }
@@ -22,20 +22,20 @@ module.exports = (send) => {
2222 }
2323
2424 try {
25- multihash = cleanMultihash ( multihash , options )
25+ cid = new CID ( cid )
2626 } catch ( err ) {
2727 return callback ( err )
2828 }
2929
30- const node = cache . get ( multihash )
30+ const node = cache . get ( cid . toString ( ) )
3131
3232 if ( node ) {
3333 return callback ( null , node . links )
3434 }
3535
3636 send ( {
3737 path : 'object/links' ,
38- args : multihash
38+ args : cid . toString ( )
3939 } , ( err , result ) => {
4040 if ( err ) {
4141 return callback ( err )
@@ -44,9 +44,7 @@ module.exports = (send) => {
4444 let links = [ ]
4545
4646 if ( result . Links ) {
47- links = result . Links . map ( ( l ) => {
48- return new DAGLink ( l . Name , l . Size , l . Hash )
49- } )
47+ links = result . Links . map ( ( l ) => new DAGLink ( l . Name , l . Size , l . Hash ) )
5048 }
5149 callback ( null , links )
5250 } )
0 commit comments