Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit f61a553

Browse files
author
Alan Shaw
committed
fix: allow CID inputs to Object API
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
1 parent e62cd6c commit f61a553

File tree

7 files changed

+23
-30
lines changed

7 files changed

+23
-30
lines changed

src/object/addLink.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
const promisify = require('promisify-es6')
44
const CID = require('cids')
5-
const cleanMultihash = require('../utils/clean-multihash')
65

76
module.exports = (send) => {
8-
return promisify((multihash, dLink, opts, callback) => {
7+
return promisify((cid, dLink, opts, callback) => {
98
if (typeof opts === 'function') {
109
callback = opts
1110
opts = {}
@@ -15,17 +14,17 @@ module.exports = (send) => {
1514
}
1615

1716
try {
18-
multihash = cleanMultihash(multihash, opts)
17+
cid = new CID(cid)
1918
} catch (err) {
2019
return callback(err)
2120
}
2221

2322
send({
2423
path: 'object/patch/add-link',
2524
args: [
26-
multihash,
25+
cid.toString(),
2726
dLink.name,
28-
cleanMultihash(dLink.cid.buffer)
27+
dLink.cid.toString()
2928
]
3029
}, (err, result) => {
3130
if (err) {

src/object/appendData.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
const promisify = require('promisify-es6')
44
const once = require('once')
55
const CID = require('cids')
6-
const cleanMultihash = require('../utils/clean-multihash')
76
const SendOneFile = require('../utils/send-one-file')
87

98
module.exports = (send) => {
109
const sendOneFile = SendOneFile(send, 'object/patch/append-data')
1110

12-
return promisify((multihash, data, opts, _callback) => {
11+
return promisify((cid, data, opts, _callback) => {
1312
if (typeof opts === 'function') {
1413
_callback = opts
1514
opts = {}
@@ -20,12 +19,12 @@ module.exports = (send) => {
2019
}
2120

2221
try {
23-
multihash = cleanMultihash(multihash, opts)
22+
cid = new CID(cid)
2423
} catch (err) {
2524
return callback(err)
2625
}
2726

28-
sendOneFile(data, { args: [multihash] }, (err, result) => {
27+
sendOneFile(data, { args: [cid.toString()] }, (err, result) => {
2928
if (err) {
3029
return callback(err)
3130
}

src/object/get.js

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const promisify = require('promisify-es6')
44
const dagPB = require('ipld-dag-pb')
55
const DAGNode = dagPB.DAGNode
66
const DAGLink = dagPB.DAGLink
7-
const bs58 = require('bs58')
87
const CID = require('cids')
98
const LRU = require('lru-cache')
109
const lruOptions = {

src/object/links.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const promisify = require('promisify-es6')
44
const dagPB = require('ipld-dag-pb')
55
const DAGLink = dagPB.DAGLink
6-
const cleanMultihash = require('../utils/clean-multihash')
6+
const CID = require('cids')
77
const LRU = require('lru-cache')
88
const lruOptions = {
99
max: 128
@@ -12,7 +12,7 @@ const lruOptions = {
1212
const cache = new LRU(lruOptions)
1313

1414
module.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
})

src/object/rmLink.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
const promisify = require('promisify-es6')
44
const CID = require('cids')
5-
const cleanMultihash = require('../utils/clean-multihash')
65

76
module.exports = (send) => {
8-
return promisify((multihash, dLink, opts, callback) => {
7+
return promisify((cid, dLink, opts, callback) => {
98
if (typeof opts === 'function') {
109
callback = opts
1110
opts = {}
@@ -15,15 +14,15 @@ module.exports = (send) => {
1514
}
1615

1716
try {
18-
multihash = cleanMultihash(multihash, opts)
17+
cid = new CID(cid)
1918
} catch (err) {
2019
return callback(err)
2120
}
2221

2322
send({
2423
path: 'object/patch/rm-link',
2524
args: [
26-
multihash,
25+
cid.toString(),
2726
dLink.name
2827
]
2928
}, (err, result) => {

src/object/setData.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
const promisify = require('promisify-es6')
44
const once = require('once')
55
const CID = require('cids')
6-
const cleanMultihash = require('../utils/clean-multihash')
76
const SendOneFile = require('../utils/send-one-file')
87

98
module.exports = (send) => {
109
const sendOneFile = SendOneFile(send, 'object/patch/set-data')
1110

12-
return promisify((multihash, data, opts, _callback) => {
11+
return promisify((cid, data, opts, _callback) => {
1312
if (typeof opts === 'function') {
1413
_callback = opts
1514
opts = {}
@@ -20,12 +19,12 @@ module.exports = (send) => {
2019
}
2120

2221
try {
23-
multihash = cleanMultihash(multihash, opts)
22+
cid = new CID(cid)
2423
} catch (err) {
2524
return callback(err)
2625
}
2726

28-
sendOneFile(data, { args: [multihash] }, (err, result) => {
27+
sendOneFile(data, { args: [cid.toString()] }, (err, result) => {
2928
if (err) {
3029
return callback(err)
3130
}

src/object/stat.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4-
const cleanMultihash = require('../utils/clean-multihash')
4+
const CID = require('cids')
55

66
module.exports = (send) => {
7-
return promisify((multihash, opts, callback) => {
7+
return promisify((cid, opts, callback) => {
88
if (typeof opts === 'function') {
99
callback = opts
1010
opts = {}
@@ -14,14 +14,14 @@ module.exports = (send) => {
1414
}
1515

1616
try {
17-
multihash = cleanMultihash(multihash, opts)
17+
cid = new CID(cid)
1818
} catch (err) {
1919
return callback(err)
2020
}
2121

2222
send({
2323
path: 'object/stat',
24-
args: multihash
24+
args: cid.toString()
2525
}, callback)
2626
})
2727
}

0 commit comments

Comments
 (0)