mirror of https://github.com/perkeep/perkeep.git
ui: simplify signing config discovery, clean up logging
Change-Id: I4e9810499b7fe34b1e7d8c32dd612cb1d6e6c348
This commit is contained in:
parent
e3bda63e68
commit
3c89f7fe97
|
@ -43,7 +43,6 @@ function setTextContent(ele, text) {
|
|||
// Method 1 to get discovery information (JSONP style):
|
||||
function onConfiguration(config) {
|
||||
Camli.config = disco = config;
|
||||
console.log("Got config: " + JSON.stringify(config));
|
||||
}
|
||||
|
||||
function saneOpts(opts) {
|
||||
|
@ -73,27 +72,6 @@ function dateToRfc3339String(dateVal) {
|
|||
pad(dateVal.getUTCHours(), 2) + ":" + pad(dateVal.getUTCMinutes(), 2) + ":" + pad(dateVal.getUTCSeconds(), 2) + "Z";
|
||||
}
|
||||
|
||||
var cachedCamliSigDiscovery;
|
||||
|
||||
// opts.success called with discovery object
|
||||
// opts.fail called with error text
|
||||
function camliSigDiscovery(opts) {
|
||||
opts = saneOpts(opts);
|
||||
if (cachedCamliSigDiscovery) {
|
||||
opts.success(cachedCamliSigDiscovery);
|
||||
return;
|
||||
}
|
||||
var cb = {};
|
||||
cb.success = function(sd) {
|
||||
cachedCamliSigDiscovery = sd;
|
||||
opts.success(sd);
|
||||
};
|
||||
cb.fail = opts.fail;
|
||||
var xhr = camliJsonXhr("camliSigDiscovery", cb);
|
||||
xhr.open("GET", Camli.config.jsonSignRoot + "/camli/sig/discovery", true);
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function camliDescribeBlob(blobref, opts) {
|
||||
var xhr = camliJsonXhr("camliDescribeBlob", opts);
|
||||
var path = Camli.config.searchRoot +
|
||||
|
@ -167,34 +145,27 @@ function camliDescribeBlogURL(blobref) {
|
|||
|
||||
function camliSign(clearObj, opts) {
|
||||
opts = saneOpts(opts);
|
||||
var sigConf = Camli.config.signing;
|
||||
if (!sigConf || !sigConf.publicKeyBlobRef) {
|
||||
camliCondCall(opts.fail, "Missing Camli.config.signing.publicKeyBlobRef");
|
||||
return;
|
||||
}
|
||||
|
||||
camliSigDiscovery(
|
||||
{
|
||||
success: function(sigConf) {
|
||||
if (!sigConf.publicKeyBlobRef) {
|
||||
opts.fail("Missing sigConf.publicKeyBlobRef");
|
||||
return;
|
||||
}
|
||||
clearObj.camliSigner = sigConf.publicKeyBlobRef;
|
||||
clearText = JSON.stringify(clearObj, null, 2);
|
||||
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);
|
||||
}
|
||||
});
|
||||
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));
|
||||
}
|
||||
|
||||
// camliUploadFile uploads a file and returns a file schema. It does not create
|
||||
|
|
|
@ -116,7 +116,6 @@ CamliIndexPage.setThumbBoxStyle = function(div) {
|
|||
// divFromResult converts the |i|th searchResult into
|
||||
// a div element, style as a thumbnail tile.
|
||||
function divFromResult(searchRes, i) {
|
||||
console.log(JSON.stringify(searchRes));
|
||||
var result = searchRes.recent[i];
|
||||
var br = searchRes[result.blobref];
|
||||
var divperm = document.createElement("div");
|
||||
|
|
Loading…
Reference in New Issue