-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy path04.js
60 lines (50 loc) · 1.35 KB
/
04.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const validate = async (result, ipfs) => {
const correctMessage = 'You did it!'
if (!result) {
return {
fail: 'Oops! You forgot to return a result :('
}
}
if (result.error) {
return { error: result.error }
}
if (typeof result !== 'string') {
return {
fail: 'Oh no... your result should be a string.'
}
}
if (result === correctMessage) {
return {
success: 'Success!',
logDesc: "Here's the secret message hidden in that file (🤫): ",
log: result
}
} else {
return { fail: `Something seems to be wrong. Please click "Reset Code" and try again, taking another look at the instructions and editing only the portion of code indicated. Feeling really stuck? You can click "View Solution" to see our suggested code.` }
}
}
const code = `/* global ipfs, toBuffer */
const run = async () => {
const fileContents = // place your code here
// don't forget to return the string value
}
return run
`
const solution = `/* global ipfs, toBuffer */
const run = async () => {
const fileContents = await toBuffer(ipfs.cat('QmWCscor6qWPdx53zEQmZvQvuWQYxx1ARRCXwYVE4s9wzJ'))
const message = new TextDecoder().decode(fileContents)
return message
}
return run
`
const options = {
overrideErrors: true,
createTestFile: true
}
export default {
validate,
code,
solution,
options
}