forked from BlockDevsUnited/ipfs-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.html
97 lines (87 loc) · 3.53 KB
/
client.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
85
86
87
88
89
90
91
92
93
94
95
96
97
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>The Client</title>
<!--link rel="stylesheet" type="text/css" href="https://ipfs.io/ipfs/QmaiJjHi59LSF3d57Jfmo7MJaXzsDhwszcKnYE8F4WUEi7/semantic.min.css"-->
<link rel="stylesheet" type="text/css" href="http://localhost:8080/ipfs/QmaiJjHi59LSF3d57Jfmo7MJaXzsDhwszcKnYE8F4WUEi7/semantic.min.css">
</head>
<script>
var run = function() {
var host = document.getElementById("ip-address").value;
var port = document.getElementById("port").value;
document.getElementById("ipfs-result").value = 'loading...';
document.getElementById("ipns-result").value = 'loading...';
fetch('http://'+host+':'+port+'/api/v0/files/stat?arg=/test.txt')
.then(data => {return data.json()})
.then(payload => {
var hash = payload.Hash;
return fetch('http://localhost:8080/ipfs/' + hash);
})
.then(data => {return data.text()})
.then(payload => {
document.getElementById("ipfs-result").value = payload;
myroot_ipns_key = 'QmQJvfVVhtPhYKujgR8BbkGSv5cM7fnyscLn7WCX86d6q6';
return fetch('http://localhost:8080/ipns/' + myroot_ipns_key);
})
.then(data => {return data.text()})
.then(payload => {
document.getElementById("ipns-result").value = payload;
})
return false;
}
</script>
<body>
<div class="ui middle aligned center aligned grid" style="margin-top:50px;">
<div class="column" style="width:450px;">
<h2 class="ui teal header">
<div class="content">
Fetch Qm hash of '/test.txt' from node:
</div>
</h2>
<form class="ui large form">
<div class="ui stacked segment">
<div class="field">
<div class="ui labeled input">
<a class="ui label" style="width:8em;">Host</a>
<input type="text" id="ip-address" value="127.0.0.1">
</div>
</div>
<div class="field">
<div class="ui labeled input">
<a class="ui label" style="width:8em;">API Port</a>
<input type="text" id="port" value="5001">
</div>
</div>
<div class="ui fluid large teal submit button" onclick="run()">Fetch</div>
</div>
</form>
</div>
</div>
<div class="ui middle aligned center aligned grid" style="margin-top:50px;">
<div class="column" style="width:450px;">
<h2 class="ui teal header">
<div class="content">
Results
</div>
</h2>
<form class="ui large form">
<div class="ui stacked segment">
<div class="field">
<div class="ui labeled input">
<a class="ui label" style="width:11em;">Latest IPFS</a>
<input disabled type="text" id="ipfs-result">
</div>
</div>
<div class="field">
<div class="ui labeled input">
<a class="ui label" style="width:11em;">Latest IPNS</a>
<input disabled type="text" id="ipns-result">
</div>
</div>
</div>
</form>
</div>
</div>
</body>
</html>