camlistored: Start adding /ui?p=... permanode viewer.

This commit is contained in:
Daniel Erat 2011-05-29 21:39:23 -07:00
parent 3f928e922b
commit 3ec25aec34
3 changed files with 63 additions and 0 deletions

View File

@ -27,6 +27,7 @@ import (
"path/filepath"
"regexp"
"camli/blobref"
"camli/blobserver"
"camli/jsonconfig"
"camli/schema"
@ -128,6 +129,10 @@ func wantsUploadHelper(req *http.Request) bool {
return req.Method == "POST" && camliMode(req) == "uploadhelper"
}
func wantsPermanode(req *http.Request) bool {
return req.Method == "GET" && blobref.Parse(req.FormValue("p")) != nil
}
func (ui *UIHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
base := req.Header.Get("X-PrefixHandler-PathBase")
suffix := req.Header.Get("X-PrefixHandler-PathSuffix")
@ -142,6 +147,8 @@ func (ui *UIHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
file := ""
if m := staticFilePattern.FindStringSubmatch(suffix); m != nil {
file = m[1]
} else if wantsPermanode(req) {
file = "permanode.html"
} else if req.URL.Path == base {
file = "index.html"
} else {

View File

@ -0,0 +1,18 @@
<html>
<head>
<title>Permanode</title>
<script type="text/javascript" src="permanode.js"></script>
<script type="text/javascript">
function fillPage() {
var permanode = getPermanodeParam();
if (permanode) {
document.getElementById('permanode').innerText = permanode;
}
}
</script>
</head>
<body onload="fillPage();">
<h1>Permanode</h1>
<p><span id="permanode"></span></p>
</body>
</html>

View File

@ -0,0 +1,38 @@
/*
Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Returns the first value from the query string corresponding to |key|.
// Returns null if the key isn't present.
function getQueryParam(key) {
var params = document.location.search.substring(1).split('&');
for (var i = 0; i < params.length; ++i) {
var parts = params[i].split('=');
if (parts.length == 2 && decodeURIComponent(parts[0]) == key)
return decodeURIComponent(parts[1]);
}
return null;
}
// Returns true if the passed-in string might be a blobref.
function isPlausibleBlobRef(blobRef) {
return /^\w+-[a-f0-9]+$/.test(blobRef);
}
// Gets the |p| query parameter, assuming that it looks like a blobref.
function getPermanodeParam() {
var blobRef = getQueryParam('p');
return (blobRef && isPlausibleBlobRef(blobRef)) ? blobRef : null;
}