@@ -5,7 +5,7 @@ const dagPB = require('ipld-dag-pb')
5
5
const DAGNode = dagPB . DAGNode
6
6
const DAGLink = dagPB . DAGLink
7
7
const bs58 = require ( 'bs58' )
8
- const cleanMultihash = require ( '../utils/clean-multihash ' )
8
+ const CID = require ( 'cids ' )
9
9
const LRU = require ( 'lru-cache' )
10
10
const lruOptions = {
11
11
max : 128
@@ -14,7 +14,7 @@ const lruOptions = {
14
14
const cache = LRU ( lruOptions )
15
15
16
16
module . exports = ( send ) => {
17
- return promisify ( ( multihash , options , callback ) => {
17
+ return promisify ( ( hash , options , callback ) => {
18
18
if ( typeof options === 'function' ) {
19
19
callback = options
20
20
options = { }
@@ -24,21 +24,24 @@ module.exports = (send) => {
24
24
options = { }
25
25
}
26
26
27
+ let cid , b58Hash
28
+
27
29
try {
28
- multihash = cleanMultihash ( multihash , options )
30
+ cid = new CID ( hash )
31
+ b58Hash = cid . toBaseEncodedString ( )
29
32
} catch ( err ) {
30
33
return callback ( err )
31
34
}
32
35
33
- const node = cache . get ( multihash )
36
+ const node = cache . get ( b58Hash )
34
37
35
38
if ( node ) {
36
39
return callback ( null , node )
37
40
}
38
41
39
42
send ( {
40
43
path : 'object/get' ,
41
- args : multihash
44
+ args : b58Hash
42
45
} , ( err , result ) => {
43
46
if ( err ) {
44
47
return callback ( err )
@@ -52,7 +55,7 @@ module.exports = (send) => {
52
55
if ( err ) {
53
56
return callback ( err )
54
57
}
55
- cache . set ( multihash , node )
58
+ cache . set ( b58Hash , node )
56
59
callback ( null , node )
57
60
} )
58
61
} )
0 commit comments