Skip to content

Commit f5b70c8

Browse files
committed
fix: 0004/10 lesson update
1 parent 5e6474a commit f5b70c8

File tree

12 files changed

+68
-54
lines changed

12 files changed

+68
-54
lines changed

DEVELOPING_TUTORIALS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ If the object returned by your `validate` function has the property `fail`, the
377377
You may (optionally) use [markdown formatting](https://guides.github.com/features/mastering-markdown/) in your `fail` or `success` messages. For example, the following validation code:
378378

379379
```js
380-
} else if (result && !result.hash) {
380+
} else if (result && !result.cid) {
381381
return { fail: "That result doesn't look right. Are you sure you ran the `stat` method on your empty root directory?" }
382382
}
383383
```

src/tutorials/0002-basics/01.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ const validate = async (result, ipfs) => {
99
return { fail: 'Did not return a valid CID instance.' }
1010
}
1111

12-
const hash = 'bafyreicaoyussrycqolu4k2iaxleu2uakjlq57tuxq3djxn4wnyfp4yk3y'
13-
if (result.toString() === hash) {
12+
if (result.toString() === 'bafyreicaoyussrycqolu4k2iaxleu2uakjlq57tuxq3djxn4wnyfp4yk3y') {
1413
return { success: 'Everything works!' }
1514
} else {
1615
const obj = await ipfs.dag.get(result)

src/tutorials/0002-basics/02.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ const validate = async (result, ipfs) => {
99
return { fail: 'Did not return a valid CID instance.' }
1010
}
1111

12-
const correctHash = 'bafyreibmdfd7c5db4kls4ty57zljfhqv36gi43l6txl44pi423wwmeskwy'
13-
if (result.toString() === correctHash) {
12+
if (result.toString() === 'bafyreibmdfd7c5db4kls4ty57zljfhqv36gi43l6txl44pi423wwmeskwy') {
1413
return { success: 'Everything works!' }
1514
} else {
1615
return { fail: `Your function returned a CID, but it doesn't have the right contents. Be sure to \`put\` an object with \`bar\` as the named link and \`cid\` as its value.` }

src/tutorials/0004-mutable-file-system/02.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import utils from '../utils'
22

33
const validate = async (result, ipfs) => {
4-
const correctHash = 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn'
5-
64
if (!result) {
75
return { fail: 'Oops! You forgot to return a result :(' }
86
} else if (!!result & !result.cid) {
97
return { fail: "That result doesn't look right. Are you sure you ran the `stat` method on your empty root directory?" }
10-
} else if (!!result && result.cid.toString() === correctHash) {
8+
} else if (!!result && result.cid.toString() === 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn') {
119
return {
1210
success: 'Success! You did it!',
1311
logDesc: "Here's the status of your root directory ( `/` ). Notice that it has a CID even though it doesn't have contents yet. Every empty IPFS node has this exact same CID, because their non-existent contents are identical!",

src/tutorials/0004-mutable-file-system/06.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const code = `/* global ipfs */
3535
const run = async (files) => {
3636
// this code adds your uploaded files to IPFS
3737
await Promise.all(files.map(f => ipfs.files.write('/' + f.name, f, { create: true })))
38-
const rootDirectoryContents = await ipfs.files.ls('/')
38+
const rootDirectoryContents = await all(ipfs.files.ls('/'))
3939
4040
const directoryStatus = // your code goes here
4141

src/tutorials/0004-mutable-file-system/07.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ const validate = async (result, ipfs) => {
2727

2828
/** CHECK FOR CORRECT /SOME/STUFF DIRECTORY **/
2929

30-
// Correct directory hash
31-
const someStuffHash = 'QmVneuc3suf78aVdvFY3BW9HoiEfNxD7WB5zu1f9fbun3D' // /some/stuff/
32-
// Common incorrect directory hashes
33-
const emptyDirectoryHash = 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' // empty /some/ OR /stuff/ directory
34-
const stuffSomeHash = 'QmXHDGVf4VnHws1tNyEcyVKjHrtv927xceAG9RmBWMw8cf' // /stuff/some/
35-
36-
// Check whether array contains certain directory hash & certain directory name
37-
function contains (certainHash, certainName) {
30+
// Correct directory CID
31+
const someStuffCID = 'QmVneuc3suf78aVdvFY3BW9HoiEfNxD7WB5zu1f9fbun3D' // /some/stuff/
32+
// Common incorrect directory CIDs
33+
const emptyDirectoryCID = 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn' // empty /some/ OR /stuff/ directory
34+
const stuffSomeCID = 'QmXHDGVf4VnHws1tNyEcyVKjHrtv927xceAG9RmBWMw8cf' // /stuff/some/
35+
36+
// Check whether array contains certain directory CID & certain directory name
37+
function contains (cid, name) {
3838
if (Array.isArray(result)) {
39-
return result.some(file => (file.cid && file.cid.toString() === certainHash) && (file.name === certainName))
39+
return result.some(file => (file.cid && file.cid.toString() === cid) && (file.name === name))
4040
}
4141
}
4242

@@ -94,26 +94,26 @@ const validate = async (result, ipfs) => {
9494
logDesc: "Here's what's in your root directory:",
9595
log: ipfsFilesInRoot.map(utils.format.ipfsObject)
9696
}
97-
} else if (contains(stuffSomeHash, 'stuff')) {
97+
} else if (contains(stuffSomeCID, 'stuff')) {
9898
// created /stuff/some instead of /some/stuff
9999
return { fail: 'Uh oh. Looks like you created /stuff/some instead of `/some/stuff`.' }
100-
} else if (contains(emptyDirectoryHash, 'stuff')) {
100+
} else if (contains(emptyDirectoryCID, 'stuff')) {
101101
// created /stuff instead of /some/stuff.
102102
return { fail: 'Uh oh. Looks like you created /stuff instead of `/some/stuff`.' }
103-
} else if (contains(emptyDirectoryHash, 'some')) {
103+
} else if (contains(emptyDirectoryCID, 'some')) {
104104
// created /some instead of /some/stuff
105105
return { fail: 'Uh oh. Looks like you created /some instead of `/some/stuff`.' }
106-
} else if (!contains(someStuffHash, 'some')) {
106+
} else if (!contains(someStuffCID, 'some')) {
107107
// didn't create empty some/stuff
108108
return { fail: 'Uh oh. Looks like your directory doesn\'t contain an empty `/some/stuff/` directory.' }
109-
} else if (contains(someStuffHash, 'some') && !contentsMatch) {
109+
} else if (contains(someStuffCID, 'some') && !contentsMatch) {
110110
// created empty /some/stuff but other files are wrong (messed up write method)
111111
return {
112112
fail: 'Hmmm. You created a `/some/stuff` directory but something else is wrong. Did you accidentally edit the default `write` code so your other files weren\'t all added?',
113113
logDesc: "Here's what was returned by `ls` in your root directory.",
114114
log: ipfsFilesInRoot.map(utils.format.ipfsObject)
115115
}
116-
} else if (contains(someStuffHash, 'some') && contentsMatch) {
116+
} else if (contains(someStuffCID, 'some') && contentsMatch) {
117117
// filenames match and created empty some/stuff
118118
return {
119119
success: 'Success! Check out your directory contents below.',

src/tutorials/0004-mutable-file-system/09.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ const validate = async (result, ipfs) => {
3838
incorrectFilenames.push('QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ')
3939
incorrectFilenames.sort()
4040

41-
// check for a file with hash QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ
42-
const someStuffHashes = someStuffFiles.map(file => file.cid.toString())
43-
const someFileHasRightHash = someStuffHashes.includes('QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ')
41+
// check for a file with CID QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ
42+
const someStuffCIDs = someStuffFiles.map(file => file.cid.toString())
43+
const someFileHasRightCID = someStuffCIDs.includes('QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ')
4444

4545
const returnedCorrectFilenames = JSON.stringify(correctFilenames) === JSON.stringify(someStuffFilenames)
46-
const returnedHashAsFilename = JSON.stringify(incorrectFilenames) === JSON.stringify(someStuffFilenames)
46+
const returnedCIDAsFilename = JSON.stringify(incorrectFilenames) === JSON.stringify(someStuffFilenames)
4747

4848
const log = someStuffFiles.map(utils.format.ipfsObject)
4949

@@ -53,10 +53,10 @@ const validate = async (result, ipfs) => {
5353
logDesc: "Did you get the desination path wrong in your `files.cp` command? Here's what's in your `/some/stuff` directory now:",
5454
log
5555
}
56-
} else if (someFileHasRightHash && returnedHashAsFilename) {
56+
} else if (someFileHasRightCID && returnedCIDAsFilename) {
5757
return {
5858
fail: 'You forgot to specify a filename.',
59-
logDesc: 'Check out the contents of your `/some/stuff` directory. You successfully copied the file but forgot to give it a name, so IPFS set its name equal to its hash. Try adding a filename to your destination path.',
59+
logDesc: 'Check out the contents of your `/some/stuff` directory. You successfully copied the file but forgot to give it a name, so IPFS set its name equal to its CID. Try adding a filename to your destination path.',
6060
log
6161
}
6262
} else if (!returnedCorrectFilenames) {
@@ -65,13 +65,13 @@ const validate = async (result, ipfs) => {
6565
logDesc: "Here's what's in your `/some/stuff` directory:",
6666
log
6767
}
68-
} else if (returnedCorrectFilenames && !someFileHasRightHash) {
68+
} else if (returnedCorrectFilenames && !someFileHasRightCID) {
6969
return {
70-
fail: 'That new file has the wrong hash.',
71-
logDesc: "Check out the contents of your `/some/stuff` directory. You created a file called `success.txt` but it doesn't have the hash we're looking for.",
70+
fail: 'That new file has the wrong CID.',
71+
logDesc: "Check out the contents of your `/some/stuff` directory. You created a file called `success.txt` but it doesn't have the CID we're looking for.",
7272
log
7373
}
74-
} else if (returnedCorrectFilenames && someFileHasRightHash) {
74+
} else if (returnedCorrectFilenames && someFileHasRightCID) {
7575
return {
7676
success: 'Success! You did it!',
7777
logDesc: 'This is the data that is now in your `/some/stuff` directory in IPFS:',

src/tutorials/0004-mutable-file-system/09.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ await ipfs.files.cp('/source-directory', '/destination-directory')
3838
await ipfs.files.cp('/ipfs/QmWGeRAEgtsHW3ec7U4qW2CyVy7eA2mFRVbk1nb24jFyks', '/destination-directory')
3939
```
4040

41-
*Gotcha!* If you copy a file from an IPFS path without explicitly assigning it a filename, IPFS will set its `name` property equal to its `hash`. To specify a more friendly filename, you'll need to append it to the destination path like so:
41+
*Gotcha!* If you copy a file from an IPFS path without explicitly assigning it a filename, IPFS will set its `name` property equal to its `CID`. To specify a more friendly filename, you'll need to append it to the destination path like so:
4242
```js
4343
await ipfs.files.cp('/ipfs/QmWGeRAEgtsHW3ec7U4qW2CyVy7eA2mFRVbk1nb24jFyks', '/destination-directory/fab-file.txt')
4444
```

src/tutorials/0004-mutable-file-system/10.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ const validate = async (result, ipfs) => {
2323
}
2424

2525
const code = `/* global ipfs */
26+
const all = require('it-all')
2627
2728
const run = async (files) => {
2829
await Promise.all(files.map(f => ipfs.files.write('/' + f.name, f, { create: true })))
2930
await ipfs.files.mkdir('/some/stuff', { parents: true })
30-
let rootDirectoryContents = await ipfs.files.ls('/', { long: true })
31+
let rootDirectoryContents = await all(ipfs.files.ls('/'))
3132
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 0).map(file => '/' + file.name)
3233
await ipfs.files.mv(filepathsToMove, '/some/stuff')
3334
await ipfs.files.cp('/ipfs/QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ', '/some/stuff/success.txt')
34-
let someStuffDirectoryContents = await ipfs.files.ls('/some/stuff', { long: true })
35+
let someStuffDirectoryContents = await all(ipfs.files.ls('/some/stuff'))
3536
3637
let secretMessage = // your code goes here
3738
@@ -42,24 +43,31 @@ return run
4243
`
4344

4445
const solution = `/* global ipfs */
46+
const all = require('it-all')
47+
const concat = require('it-concat')
4548
4649
const run = async (files) => {
4750
await Promise.all(files.map(f => ipfs.files.write('/' + f.name, f, { create: true })))
4851
await ipfs.files.mkdir('/some/stuff', { parents: true })
49-
let rootDirectoryContents = await ipfs.files.ls('/', { long: true })
52+
let rootDirectoryContents = await all(ipfs.files.ls('/'))
5053
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 0).map(file => '/' + file.name)
5154
await ipfs.files.mv(filepathsToMove, '/some/stuff')
5255
await ipfs.files.cp('/ipfs/QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ', '/some/stuff/success.txt')
53-
let someStuffDirectoryContents = await ipfs.files.ls('/some/stuff', { long: true })
56+
let someStuffDirectoryContents = await all(ipfs.files.ls('/some/stuff'))
5457
55-
let secretMessage = (await ipfs.files.read('/some/stuff/success.txt')).toString('utf8')
58+
let secretMessage = (await concat(ipfs.files.read('/some/stuff/success.txt'))).toString('utf8')
5659
5760
return secretMessage
5861
}
5962
6063
return run
6164
`
6265

66+
const modules = {
67+
'it-all': require('it-all'),
68+
'it-concat': require('it-concat')
69+
}
70+
6371
const options = {
6472
overrideErrors: true,
6573
createTestFile: true
@@ -69,5 +77,6 @@ export default {
6977
validate,
7078
code,
7179
solution,
80+
modules,
7281
options
7382
}

src/tutorials/0004-mutable-file-system/11.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1+
import all from 'it-all'
2+
3+
import utils from '../utils'
4+
15
const validate = async (result, ipfs) => {
2-
const rootDirectoryContents = await ipfs.files.ls('/', { long: true })
6+
const rootDirectoryContents = await all(ipfs.files.ls('/'))
37
const rootDirectoryStatus = await ipfs.files.stat('/')
4-
const rootIsEmpty = rootDirectoryStatus.hash === 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn'
8+
const rootIsEmpty = rootDirectoryStatus.cid && rootDirectoryStatus.cid.toString() === 'QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn'
59

610
let rootContainsSome = rootDirectoryContents.length === 1 && rootDirectoryContents[0].name === 'some'
711
let someContainsStuff = null
812
let someIsEmpty = null
913
let someDirectoryContents = null
1014

1115
if (rootContainsSome) {
12-
someDirectoryContents = await ipfs.files.ls('/some', { long: true })
16+
someDirectoryContents = await all(ipfs.files.ls('/some'))
1317
someContainsStuff = someDirectoryContents.length === 1 && someDirectoryContents[0].name === 'stuff'
1418
someIsEmpty = someDirectoryContents.length === 0
1519
}
@@ -21,7 +25,7 @@ const validate = async (result, ipfs) => {
2125
fail: 'Oops! You tried to remove a non-empty directory and it didn\'t work because you forgot to use `{ recursive: true }`.',
2226
overrideError: true
2327
}
24-
} else if (!rootDirectoryStatus.hash) {
28+
} else if (!rootDirectoryStatus.cid) {
2529
return { fail: 'Your root directory doesn\'t look right. Are you sure you ran the `files.rm` method on your `/some` directory with the option `{ recursive: true }`?' }
2630
} else if (result instanceof Error && result.message === 'Cannot delete root') {
2731
return {
@@ -42,57 +46,61 @@ const validate = async (result, ipfs) => {
4246
return {
4347
fail: 'Your root directory isn\'t empty. Are you sure you ran the `files.rm` method on your `/some` directory with the option `{ recursive: true }`?',
4448
logDesc: 'Here are the current contents of your root directory:',
45-
log: JSON.stringify(rootDirectoryContents, null, 2)
49+
log: rootDirectoryContents.map(utils.format.ipfsObject)
4650
}
4751
} else if (rootIsEmpty) {
4852
return {
4953
success: 'Success! You\'ve completed this series of lessons!',
5054
logDesc: "Your function returned an empty array (`[]`) as there is no content in your root directory. Its status (`stat`) is shown below. Note that we're back to exactly the same CID we started with!",
51-
log: JSON.stringify(rootDirectoryStatus, null, 2)
55+
log: utils.format.ipfsObject(rootDirectoryStatus)
5256
}
5357
}
5458
}
5559

5660
const code = `/* global ipfs */
61+
const all = require('it-all')
5762
5863
const run = async (files) => {
5964
await Promise.all(files.map(f => ipfs.files.write('/' + f.name, f, { create: true })))
6065
await ipfs.files.mkdir('/some/stuff', { parents: true })
61-
let rootDirectoryContents = await ipfs.files.ls('/', { long: true })
66+
let rootDirectoryContents = await all(ipfs.files.ls('/'))
6267
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 0).map(file => '/' + file.name)
6368
await ipfs.files.mv(filepathsToMove, '/some/stuff')
6469
await ipfs.files.cp('/ipfs/QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ', '/some/stuff/success.txt')
65-
let someStuffDirectoryContents = await ipfs.files.ls('/some/stuff', { long: true })
70+
let someStuffDirectoryContents = await all(ipfs.files.ls('/some/stuff'))
6671
6772
// Your code goes here
6873
69-
let finalRootDirectoryContents = await ipfs.files.ls('/', { long: true })
74+
let finalRootDirectoryContents = await all(ipfs.files.ls('/'))
7075
return finalRootDirectoryContents
7176
}
7277
7378
return run
7479
`
7580

7681
const solution = `/* global ipfs */
82+
const all = require('it-all')
7783
7884
const run = async (files) => {
7985
await Promise.all(files.map(f => ipfs.files.write('/' + f.name, f, { create: true })))
8086
await ipfs.files.mkdir('/some/stuff', { parents: true })
81-
let rootDirectoryContents = await ipfs.files.ls('/', { long: true })
87+
let rootDirectoryContents = await all(ipfs.files.ls('/'))
8288
const filepathsToMove = rootDirectoryContents.filter(file => file.type === 0).map(file => '/' + file.name)
8389
await ipfs.files.mv(filepathsToMove, '/some/stuff')
8490
await ipfs.files.cp('/ipfs/QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ', '/some/stuff/success.txt')
85-
let someStuffDirectoryContents = await ipfs.files.ls('/some/stuff', { long: true })
91+
let someStuffDirectoryContents = await all(ipfs.files.ls('/some/stuff'))
8692
8793
await ipfs.files.rm('/some', { recursive: true })
8894
89-
let finalRootDirectoryContents = await ipfs.files.ls('/', { long: true })
95+
let finalRootDirectoryContents = await all(ipfs.files.ls('/'))
9096
return finalRootDirectoryContents
9197
}
9298
9399
return run
94100
`
95101

102+
const modules = { 'it-all': require('it-all') }
103+
96104
const options = {
97105
overrideErrors: true,
98106
createTestFile: true
@@ -102,5 +110,6 @@ export default {
102110
validate,
103111
code,
104112
solution,
113+
modules,
105114
options
106115
}

src/tutorials/0005-regular-files-api/06.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The `ls` method in the Regular Files API returns an array of objects, one for ea
2323

2424
```javascript
2525
{
26-
"hash": string,
26+
"cid": Object,
2727
"path": string,
2828
"name": string,
2929
"depth": number,

src/tutorials/0005-regular-files-api/08.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The result is an array of objects, one per file or directory, with the following
1313

1414
```javascript
1515
{
16-
hash: string,
16+
cid: Object,
1717
name: string,
1818
path: string,
1919
depth: number,

0 commit comments

Comments
 (0)