-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipad.html
84 lines (63 loc) · 2.35 KB
/
ipad.html
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>IPFS iPad Test</title>
<script src="https://unpkg.com/ipfs-api/dist/index.min.js"></script>
<script src="https://unpkg.com/ipfs/dist/index.min.js"></script>
</head>
<body>
<p id="useragent"></p>
<p id="link"></p>
<script>
var userAgentElem = document.getElementById('useragent');
userAgentElem.appendChild(document.createTextNode(navigator.userAgent ));
var Buffer = window.IpfsApi().Buffer;
// var repoPath = 'ipfs-' + Math.random();
// // Create an IPFS node
// var node = new Ipfs({
// init: false,
// start: false,
// repo: repoPath
// });
const node = new Ipfs({
config: {
Addresses: {
Swarm: []
}
}
});
// Init the node
node.init(handleInit);
function handleInit(err) {
if (err) {
throw err;
}
node.start(function() {
console.log('Online status: ', node.isOnline() ? 'online' : 'offline');
var data = {
test: Date.now() + Math.random()
}
var stringified = JSON.stringify(data);
console.log(stringified);
node.files.add(Buffer.from(stringified), function (err, res) {
console.log("added");
if (err || !res) {
return console.error('Error - ipfs files add', err, res)
}
res.forEach(function(file) {
var linkElem = document.getElementById("link");
var aTag = document.createElement('a');
aTag.setAttribute('href', "http://ipfs.io/ipfs/" + file.hash);
aTag.setAttribute('target',"_blank");
aTag.setAttribute('id',"link");
aTag.innerHTML = file.hash;
linkElem.appendChild(aTag);
});
});
});
}
</script>
</body>
</html>