This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy pathApp.js
63 lines (61 loc) · 1.61 KB
/
App.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
61
62
63
'use strict'
const React = require('react')
const ipfsAPI = require('ipfs-api')
const ipfs = ipfsAPI('localhost', '5001')
const stringToUse = 'hello world from webpacked IPFS'
class App extends React.Component {
constructor (props) {
super(props)
this.state = {
id: null,
version: null,
protocol_version: null,
added_file_hash: null,
added_file_contents: null
}
}
componentDidMount () {
ipfs.id((err, res) => {
if (err) throw err
this.setState({
id: res.id,
version: res.agentVersion,
protocol_version: res.protocolVersion
})
})
ipfs.add([new Buffer(stringToUse)], (err, res) => {
if (err) throw err
const hash = res[0].hash
this.setState({added_file_hash: hash})
ipfs.cat(hash, (err, res) => {
if (err) throw err
let data = ''
res.on('data', (d) => {
data = data + d
})
res.on('end', () => {
this.setState({added_file_contents: data})
})
})
})
}
render () {
return <div style={{textAlign: 'center'}}>
<h1>Everything is working!</h1>
<p>Your ID is <strong>{this.state.id}</strong></p>
<p>Your IPFS version is <strong>{this.state.version}</strong></p>
<p>Your IPFS protocol version is <strong>{this.state.protocol_version}</strong></p>
<div>
<div>
Added a file! <br />
{this.state.added_file_hash}
</div>
<div>
Contents of this file: <br />
{this.state.added_file_contents}
</div>
</div>
</div>
}
}
module.exports = App