mirror of https://github.com/perkeep/perkeep.git
UI work; permanode creation (but not upload)
This commit is contained in:
parent
3f928e922b
commit
4b66f0dcca
|
@ -2,6 +2,7 @@
|
|||
<head>
|
||||
<title>Camlistored UI</title>
|
||||
<script src="ui.js"></script>
|
||||
<script src="sigdebug.js"></script>
|
||||
<script src="./?camli.mode=config&cb=onConfiguration"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -1,15 +1,31 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Camlistored UI</title>
|
||||
<script type="text/javascript" src="base64.js"></script>
|
||||
<script type="text/javascript" src="Crypto.js"></script>
|
||||
<script type="text/javascript" src="SHA1.js"></script>
|
||||
<script src="ui.js"></script>
|
||||
<script src="?camli.mode=config&cb=onConfiguration"></script>
|
||||
<style>
|
||||
#btnnew {
|
||||
font-size: 45px;
|
||||
font-family: sans;
|
||||
padding: 0.25em;
|
||||
background: #008aff;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Camlistored UI</h1>
|
||||
<p>[<b>Debug:</b>
|
||||
<a href="disco.html">discovery</a> |
|
||||
<a href="signing.html">signing</a> |
|
||||
<a href="search.html">search</a>]</p>
|
||||
<a href="search.html">search</a> |
|
||||
<a href="files.html">jsfiles</a>]</p>
|
||||
|
||||
<input type='button' value='New' id="btnNew" /> - create a new item or collection
|
||||
|
||||
<h2>Upload</h2>
|
||||
<form method="POST" id='uploadform' enctype="multipart/form-data">
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
var sigdisco = null;
|
||||
|
||||
function discoverJsonSign() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState != 4) { return; }
|
||||
if (xhr.status != 200) {
|
||||
console.log("no status 200; got " + xhr.status);
|
||||
return;
|
||||
}
|
||||
sigdisco = JSON.parse(xhr.responseText);
|
||||
document.getElementById("sigdiscores").innerHTML = JSON.stringify(sigdisco);
|
||||
};
|
||||
xhr.open("GET", disco.jsonSignRoot + "/camli/sig/discovery", true);
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function addKeyRef() {
|
||||
if (!sigdisco) {
|
||||
alert("must do jsonsign discovery first");
|
||||
return;
|
||||
}
|
||||
clearta = document.getElementById("clearjson");
|
||||
var j;
|
||||
try {
|
||||
j = JSON.parse(clearta.value);
|
||||
} catch (x) {
|
||||
alert(x);
|
||||
return
|
||||
}
|
||||
j.camliSigner = sigdisco.publicKeyBlobRef;
|
||||
clearta.value = JSON.stringify(j);
|
||||
}
|
||||
|
||||
function doSign() {
|
||||
if (!sigdisco) {
|
||||
alert("must do jsonsign discovery first");
|
||||
return;
|
||||
}
|
||||
clearta = document.getElementById("clearjson");
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState != 4) { return; }
|
||||
if (xhr.status != 200) {
|
||||
alert("got status " + xhr.status)
|
||||
return;
|
||||
}
|
||||
document.getElementById("signedjson").value = xhr.responseText;
|
||||
};
|
||||
xhr.open("POST", sigdisco.signHandler, true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("json=" + encodeURIComponent(clearta.value));
|
||||
}
|
||||
|
||||
function doVerify() {
|
||||
if (!sigdisco) {
|
||||
alert("must do jsonsign discovery first");
|
||||
return;
|
||||
}
|
||||
|
||||
signedta = document.getElementById("signedjson");
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState != 4) { return; }
|
||||
if (xhr.status != 200) {
|
||||
alert("got status " + xhr.status)
|
||||
return;
|
||||
}
|
||||
document.getElementById("verifyinfo").innerHTML = "<pre>" + xhr.responseText + "</pre>";
|
||||
};
|
||||
xhr.open("POST", sigdisco.verifyHandler, true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("sjson=" + encodeURIComponent(signedta.value));
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
<head>
|
||||
<title>Camlistored UI</title>
|
||||
<script src="ui.js"></script>
|
||||
<script src="sigdebug.js"></script>
|
||||
<script src="./?camli.mode=config&cb=onConfiguration"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -38,82 +38,74 @@ function discover() {
|
|||
xhr.send();
|
||||
}
|
||||
|
||||
var sigdisco = null;
|
||||
function saneOpts(opts) {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
if (!opts.success) {
|
||||
opts.success = function() {};
|
||||
}
|
||||
if (!opts.fail) {
|
||||
opts.fail = function() {};
|
||||
}
|
||||
return opts;
|
||||
}
|
||||
|
||||
function discoverJsonSign() {
|
||||
var cachedCamliSigDiscovery;
|
||||
|
||||
function camliSigDiscovery(opts) {
|
||||
opts = saneOpts(opts);
|
||||
if (cachedCamliSigDiscovery) {
|
||||
opts.success(cachedCamliSigDiscovery);
|
||||
return;
|
||||
}
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState != 4) { return; }
|
||||
if (xhr.status != 200) {
|
||||
console.log("no status 200; got " + xhr.status);
|
||||
opts.fail("no status 200; got " + xhr.status);
|
||||
return;
|
||||
}
|
||||
sigdisco = JSON.parse(xhr.responseText);
|
||||
document.getElementById("sigdiscores").innerHTML = JSON.stringify(sigdisco);
|
||||
cachedCamliSigDiscovery = sigdisco;
|
||||
opts.success(sigdisco);
|
||||
};
|
||||
xhr.open("GET", disco.jsonSignRoot + "/camli/sig/discovery", true);
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function addKeyRef() {
|
||||
if (!sigdisco) {
|
||||
alert("must do jsonsign discovery first");
|
||||
return;
|
||||
}
|
||||
clearta = document.getElementById("clearjson");
|
||||
var j;
|
||||
try {
|
||||
j = JSON.parse(clearta.value);
|
||||
} catch (x) {
|
||||
alert(x);
|
||||
return
|
||||
}
|
||||
j.camliSigner = sigdisco.publicKeyBlobRef;
|
||||
clearta.value = JSON.stringify(j);
|
||||
function camliSign(clearObj, opts) {
|
||||
opts = saneOpts(opts);
|
||||
|
||||
camliSigDiscovery(
|
||||
{
|
||||
success: function(sigConf) {
|
||||
if (!sigConf.publicKeyBlobRef) {
|
||||
opts.fail("Missing sigConf.publicKeyBlobRef");
|
||||
return;
|
||||
}
|
||||
clearObj.camliSigner = sigConf.publicKeyBlobRef;
|
||||
clearText = JSON.stringify(clearObj, null, 2);
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState != 4) { return; }
|
||||
if (xhr.status != 200) {
|
||||
opts.fail("got status " + xhr.status);
|
||||
return;
|
||||
}
|
||||
opts.success(xhr.responseText);
|
||||
};
|
||||
xhr.open("POST", sigConf.signHandler, true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("json=" + encodeURIComponent(clearText));
|
||||
},
|
||||
fail: function(errMsg) {
|
||||
opts.fail(errMsg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function doSign() {
|
||||
if (!sigdisco) {
|
||||
alert("must do jsonsign discovery first");
|
||||
return;
|
||||
}
|
||||
clearta = document.getElementById("clearjson");
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState != 4) { return; }
|
||||
if (xhr.status != 200) {
|
||||
alert("got status " + xhr.status)
|
||||
return;
|
||||
}
|
||||
document.getElementById("signedjson").value = xhr.responseText;
|
||||
};
|
||||
xhr.open("POST", sigdisco.signHandler, true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("json=" + encodeURIComponent(clearta.value));
|
||||
}
|
||||
|
||||
function doVerify() {
|
||||
if (!sigdisco) {
|
||||
alert("must do jsonsign discovery first");
|
||||
return;
|
||||
}
|
||||
|
||||
signedta = document.getElementById("signedjson");
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState != 4) { return; }
|
||||
if (xhr.status != 200) {
|
||||
alert("got status " + xhr.status)
|
||||
return;
|
||||
}
|
||||
document.getElementById("verifyinfo").innerHTML = "<pre>" + xhr.responseText + "</pre>";
|
||||
};
|
||||
xhr.open("POST", sigdisco.verifyHandler, true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send("sjson=" + encodeURIComponent(signedta.value));
|
||||
}
|
||||
|
||||
function search() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
@ -128,3 +120,30 @@ function search() {
|
|||
xhr.open("GET", disco.searchRoot + "camli/search", true);
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
|
||||
|
||||
function createNewPermanode() {
|
||||
var json = {
|
||||
"camliVersion": 1,
|
||||
"camliType": "permanode",
|
||||
"random": ""+Math.random()
|
||||
};
|
||||
camliSign(json, {
|
||||
success: function(got) {
|
||||
alert("got signed: " + got);
|
||||
},
|
||||
fail: function(msg) {
|
||||
alert("sign fail: " + msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function camliOnload(e) {
|
||||
var btnNew = document.getElementById("btnNew");
|
||||
if (btnNew) {
|
||||
btnNew.addEventListener("click", createNewPermanode);
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("load", camliOnload);
|
Loading…
Reference in New Issue