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

Commit d5365de

Browse files
committed
fix: only accept cid for ipfs.dag.get
If you have a path within the DAG to resolve, pass it as `path` in the options object as per the documentation. Fixes #3637
1 parent 46618c7 commit d5365de

File tree

4 files changed

+11
-22
lines changed

4 files changed

+11
-22
lines changed

examples/traverse-ipld-graphs/get-path.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ async function main () {
1515
const cid = await ipfs.dag.put(myData, { format: 'dag-cbor', hashAlg: 'sha2-256' })
1616
let result
1717

18-
result = await ipfs.dag.get(cid, 'name')
18+
result = await ipfs.dag.get(cid, { path: 'name' })
1919
console.log(result.value)
2020

21-
result = await ipfs.dag.get(cid, 'likes')
21+
result = await ipfs.dag.get(cid, { path: 'likes' })
2222
console.log(result.value)
2323

24-
result = await ipfs.dag.get(cid + '/likes/0')
24+
result = await ipfs.dag.get(cid, { path: '/likes/0' })
2525
console.log(result.value)
2626
}
2727

examples/traverse-ipld-graphs/git.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ async function main () {
5656
console.log(result.value)
5757
}
5858

59-
await logResult(() => ipfs.dag.get(v1tag + '/'), 'Tag object:')
60-
await logResult(() => ipfs.dag.get(v1tag + '/object/message'), 'Tagged commit message:')
61-
await logResult(() => ipfs.dag.get(v1tag + '/object/parents/0/message'), 'Parent of tagged commit:')
62-
await logResult(() => ipfs.dag.get(v1tag + '/object/tree/src/hash/hello/hash'), '/src/hello file:')
63-
await logResult(() => ipfs.dag.get(v1tag + '/object/parents/0/tree/src/hash/hello/hash'), 'previous version of /src/hello file:')
59+
await logResult(() => ipfs.dag.get(v1tag), 'Tag object:')
60+
await logResult(() => ipfs.dag.get(v1tag, { path: '/object/message' }), 'Tagged commit message:')
61+
await logResult(() => ipfs.dag.get(v1tag, { path: '/object/parents/0/message' }), 'Parent of tagged commit:')
62+
await logResult(() => ipfs.dag.get(v1tag, { path: '/object/tree/src/hash/hello/hash' }), '/src/hello file:')
63+
await logResult(() => ipfs.dag.get(v1tag, { path: '/object/parents/0/tree/src/hash/hello/hash' }), 'previous version of /src/hello file:')
6464
}
6565

6666
main()

packages/interface-ipfs-core/src/dag/get.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,8 @@ module.exports = (common, options) => {
146146
expect(cid).to.eql(cidCbor)
147147
})
148148

149-
it('should get by CID string + path', async function () {
150-
const cidCborStr = cidCbor.toBaseEncodedString()
151-
152-
const result = await ipfs.dag.get(cidCborStr + '/pb/Data')
149+
it('should get by CID with path option', async function () {
150+
const result = await ipfs.dag.get(cidCbor, { path: '/pb/Data' })
153151
expect(result.value).to.eql(uint8ArrayFromString('I am inside a Protobuf'))
154152
})
155153

packages/ipfs-core/src/components/dag/get.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,7 @@ module.exports = ({ ipld, preload }) => {
1414
/**
1515
* @type {import('ipfs-core-types/src/dag').API["get"]}
1616
*/
17-
const get = async function get (ipfsPath, options = {}) {
18-
const {
19-
cid,
20-
path
21-
} = toCidAndPath(ipfsPath)
22-
23-
if (path) {
24-
options.path = path
25-
}
26-
17+
const get = async function get (cid, options = {}) {
2718
if (options.preload !== false) {
2819
preload(cid)
2920
}

0 commit comments

Comments
 (0)