Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit ca59a46

Browse files
committed
fix: don't break backwards compatibility on the Block API
1 parent e630704 commit ca59a46

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/core/components/block.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ module.exports = function block (self) {
1919
block = new Block(block)
2020
}
2121

22+
if (typeof cid === 'function') {
23+
// legacy (without CID)
24+
callback = cid
25+
cid = new CID(block.key('sha2-256'))
26+
}
27+
2228
self._blockService.put({
2329
block: block,
2430
cid: cid
@@ -47,8 +53,10 @@ module.exports = function block (self) {
4753
}
4854

4955
function cleanCid (cid) {
50-
if (typeof cid === 'string') {
51-
return new CID(cid)
56+
if (cid.constructor.name === 'CID') {
57+
return cid
5258
}
53-
return cid
59+
60+
// CID constructor knows how to do the cleaning :)
61+
return new CID(cid)
5462
}

0 commit comments

Comments
 (0)