diff --git a/server/go/camlistored/ui.go b/server/go/camlistored/ui.go index 3ca7f6102..8c7acf988 100644 --- a/server/go/camlistored/ui.go +++ b/server/go/camlistored/ui.go @@ -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 { diff --git a/server/go/camlistored/ui/files.html b/server/go/camlistored/ui/files.html index 5538b9c74..251e98b35 100644 --- a/server/go/camlistored/ui/files.html +++ b/server/go/camlistored/ui/files.html @@ -16,4 +16,4 @@ or:
(drop files here)
- + diff --git a/server/go/camlistored/ui/permanode.html b/server/go/camlistored/ui/permanode.html new file mode 100644 index 000000000..fee9c4adc --- /dev/null +++ b/server/go/camlistored/ui/permanode.html @@ -0,0 +1,18 @@ + + + Permanode + + + + +

Permanode

+

+ + diff --git a/server/go/camlistored/ui/permanode.js b/server/go/camlistored/ui/permanode.js new file mode 100644 index 000000000..55aa1c217 --- /dev/null +++ b/server/go/camlistored/ui/permanode.js @@ -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; +} diff --git a/server/go/camlistored/ui/ui.js b/server/go/camlistored/ui/ui.js index 9fd572503..9ca793bc3 100644 --- a/server/go/camlistored/ui/ui.js +++ b/server/go/camlistored/ui/ui.js @@ -106,7 +106,6 @@ function camliSign(clearObj, opts) { }); } - function search() { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { @@ -177,12 +176,13 @@ function createNewPermanode() { got, { success: function(blobref) { - alert("uploaded permanode blobref: " + blobref); + // alert("uploaded permanode blobref: " + blobref); + window.location = "./?p=" + blobref; }, fail: function(msg) { alert("upload permanode fail: " + msg); } - }) + }); }, fail: function(msg) { alert("sign fail: " + msg); @@ -197,4 +197,4 @@ function camliOnload(e) { } } -window.addEventListener("load", camliOnload); \ No newline at end of file +window.addEventListener("load", camliOnload);