Try out showing the IPFS hash

This commit is contained in:
Mats Rauhala 2018-09-29 22:08:05 +03:00
parent f355516c1d
commit 213442ac0f
4 changed files with 38 additions and 0 deletions

22
js/api.js Normal file
View File

@ -0,0 +1,22 @@
var getApiIpfsCurrent = function(onSuccess, onError) {
var xhr = new XMLHttpRequest();
xhr.open('GET', '/api/ipfs/current', true);
xhr.setRequestHeader('Accept', 'application/json');
xhr.onreadystatechange = function () {
var res = null;
if (xhr.readyState === 4) {
if (xhr.status === 204 || xhr.status === 205) {
onSuccess();
} else if (xhr.status >= 200 && xhr.status < 300) {
try { res = JSON.parse(xhr.responseText); } catch (e) { onError(e); }
if (res) onSuccess(res);
} else {
try { res = JSON.parse(xhr.responseText); } catch (e) { onError(e); }
if (res) onError(res);
}
}
};
xhr.send(null);
};

10
js/app.js Normal file
View File

@ -0,0 +1,10 @@
$(document).ready(function() {
var success = function(x) {
$("#ipfs > em").html(x);
};
var error = function(x) {
$("#ipfs").hide();
console.log("ipfs hash not found: " + x);
};
getApiIpfsCurrent(success, error);
});

2
js/jquery-3.3.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -30,6 +30,10 @@
<footer>
Site proudly generated by
<a href="http://jaspervdj.be/hakyll">Hakyll</a>
<span id="ipfs">and found on IPFS as <em></em></ipfs>
</footer>
</body>
<script type="application/javascript" src="/js/jquery-3.3.1.min.js"></script>
<script type="application/javascript" src="/js/api.js"></script>
<script type="application/javascript" src="/js/app.js"></script>
</html>