forked from ipfs-inactive/js-ipfs-http-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (29 loc) · 849 Bytes
/
index.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
'use strict'
var IPFS = require('ipfs-http-client')
var ipfs = IPFS()
function store () {
var toStore = document.getElementById('source').value
ipfs.add(Buffer.from(toStore), function (err, res) {
if (err || !res) {
return console.error('ipfs add error', err, res)
}
res.forEach(function (file) {
if (file && file.hash) {
console.log('successfully stored', file.hash)
display(file.hash)
}
})
})
}
function display (hash) {
ipfs.cat(hash, function (err, res) {
if (err || !res) {
return console.error('ipfs cat error', err, res)
}
document.getElementById('hash').innerText = hash
document.getElementById('content').innerText = res.toString()
})
}
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('store').onclick = store
})