Skip to content

Commit dda1bd3

Browse files
authored
Use CIDv1 by default (#2402)
1 parent 6177b51 commit dda1bd3

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/add-to-ipfs.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async function getShareableCid (ipfs, files) {
4040
// because it handles HAMT-sharding of big directories automatically
4141
// See: https://github.com/ipfs/go-ipfs/issues/8106
4242
const dirpath = `/zzzz_${Date.now()}`
43-
await ipfs.files.mkdir(dirpath, {})
43+
await ipfs.files.mkdir(dirpath, { cidVersion: 1 })
4444

4545
for (const { cid, filename } of files) {
4646
await ipfs.files.cp(`/ipfs/${cid}`, `${dirpath}/${filename}`)
@@ -88,12 +88,19 @@ async function addFileOrDirectory (ipfs, filepath) {
8888
let cid = null
8989

9090
if (stat.isDirectory()) {
91-
const files = globSource(filepath, '**/*', { recursive: true })
92-
const res = await last(ipfs.addAll(files, { pin: false, wrapWithDirectory: true }))
91+
const files = globSource(filepath, '**/*', { recursive: true, cidVersion: 1 })
92+
const res = await last(ipfs.addAll(files, {
93+
pin: false,
94+
wrapWithDirectory: true,
95+
cidVersion: 1
96+
}))
9397
cid = res.cid
9498
} else {
9599
const readStream = fs.createReadStream(filepath)
96-
const res = await ipfs.add(readStream, { pin: false })
100+
const res = await ipfs.add(readStream, {
101+
pin: false,
102+
cidVersion: 1
103+
})
97104
cid = res.cid
98105
}
99106

test/unit/add-to-ipfs.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ test.describe('Add To Ipfs', function () {
4444
expect(electron.clipboard.writeText.callCount).toEqual(1)
4545
expect(notify.notifyError.callCount).toEqual(0)
4646
expect(notify.notify.callCount).toEqual(1)
47-
expect(cid.toString()).toEqual('QmWGeRAEgtsHW3ec7U4qW2CyVy7eA2mFRVbk1nb24jFyks')
47+
expect(cid.toString()).toEqual('bafkreibrl5n5w5wqpdcdxcwaazheualemevr7ttxzbutiw74stdvrfhn2m')
4848
})
4949

5050
test('add to ipfs single directory', async () => {
5151
const cid = await addToIpfs(ctx, getFixtures('dir'))
5252
expect(electron.clipboard.writeText.callCount).toEqual(1)
5353
expect(notify.notifyError.callCount).toEqual(0)
5454
expect(notify.notify.callCount).toEqual(1)
55-
expect(cid.toString()).toEqual('QmVuxXkWEyCKvQiMqVnDiwyJUUyDQZ7VsKhQDCZzPj1Yq8')
55+
expect(cid.toString()).toEqual('bafybeieyzpi3qdqtj7b7hfzdpt2mnmaiicvtrj7ngmf2fc76byecj62gea')
5656
})
5757

5858
test('add to ipfs multiple files', async () => {
5959
const cid = await addToIpfs(ctx, getFixtures('dir', 'hello-world.txt'))
6060
expect(electron.clipboard.writeText.callCount).toEqual(1)
6161
expect(notify.notifyError.callCount).toEqual(0)
6262
expect(notify.notify.callCount).toEqual(1)
63-
expect(cid.toString()).toEqual('QmdYASNGKMVK4HL1uzi3VCZyjQGg3M6VuLsgX5xTKL1gvH')
63+
expect(cid.toString()).toEqual('bafybeiaqy3wawya5ryds5zs4nsxv7ulptbdtgfngipqin7ee65azaxs2uq')
6464
})
6565
})

0 commit comments

Comments
 (0)