mirror of https://github.com/perkeep/perkeep.git
Merge, use Dan's stuff from Permanode creation button
This commit is contained in:
commit
121290c9d1
|
@ -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 {
|
||||
|
|
|
@ -16,4 +16,4 @@ or:
|
|||
<div id='dnd' style="border: 2px dashed black; min-height: 250px"><i>(drop files here)</i></div>
|
||||
|
||||
</body>
|
||||
</form>
|
||||
</html>
|
||||
|
|
|
@ -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>
|
|
@ -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;
|
||||
}
|
|
@ -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);
|
||||
window.addEventListener("load", camliOnload);
|
||||
|
|
Loading…
Reference in New Issue