mirror of https://github.com/perkeep/perkeep.git
Start of publish handler.
Change-Id: I229c9e00a19aa985050373beda696c5468a94105
This commit is contained in:
parent
91db635396
commit
0d7581ede6
|
@ -8,6 +8,16 @@
|
|||
"stealth": false
|
||||
}
|
||||
},
|
||||
|
||||
"/www/": {
|
||||
"handler": "publish",
|
||||
"handlerArgs": {
|
||||
"blobRoot": "/bs/",
|
||||
"searchRoot": "/my-search/",
|
||||
"cache": "/cache/"
|
||||
}
|
||||
},
|
||||
|
||||
"/ui/": {
|
||||
"handler": "ui",
|
||||
"handlerArgs": {
|
||||
|
|
|
@ -36,7 +36,7 @@ func init() {
|
|||
blobserver.RegisterHandlerConstructor("search", newHandlerFromConfig)
|
||||
}
|
||||
|
||||
type searchHandler struct {
|
||||
type Handler struct {
|
||||
index Index
|
||||
owner *blobref.BlobRef
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ func newHandlerFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (http.Handl
|
|||
return nil, fmt.Errorf("search 'owner' has malformed blobref %q; expecting e.g. sha1-xxxxxxxxxxxx",
|
||||
ownerBlobStr)
|
||||
}
|
||||
return &searchHandler{
|
||||
return &Handler{
|
||||
index: indexer,
|
||||
owner: ownerBlobRef,
|
||||
}, nil
|
||||
|
@ -76,7 +76,7 @@ func jsonMapList() []map[string]interface{} {
|
|||
return make([]map[string]interface{}, 0)
|
||||
}
|
||||
|
||||
func (sh *searchHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
func (sh *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
_ = req.Header.Get("X-PrefixHandler-PathBase")
|
||||
suffix := req.Header.Get("X-PrefixHandler-PathSuffix")
|
||||
|
||||
|
@ -104,7 +104,7 @@ func (sh *searchHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
|||
httputil.ReturnJson(rw, ret)
|
||||
}
|
||||
|
||||
func (sh *searchHandler) serveRecentPermanodes(rw http.ResponseWriter, req *http.Request) {
|
||||
func (sh *Handler) serveRecentPermanodes(rw http.ResponseWriter, req *http.Request) {
|
||||
ret := jsonMap()
|
||||
defer httputil.ReturnJson(rw, ret)
|
||||
|
||||
|
@ -138,7 +138,7 @@ func (sh *searchHandler) serveRecentPermanodes(rw http.ResponseWriter, req *http
|
|||
ret["recent"] = recent
|
||||
}
|
||||
|
||||
func (sh *searchHandler) serveClaims(rw http.ResponseWriter, req *http.Request) {
|
||||
func (sh *Handler) serveClaims(rw http.ResponseWriter, req *http.Request) {
|
||||
ret := jsonMap()
|
||||
|
||||
pn := blobref.Parse(req.FormValue("permanode"))
|
||||
|
@ -178,7 +178,7 @@ func (sh *searchHandler) serveClaims(rw http.ResponseWriter, req *http.Request)
|
|||
}
|
||||
|
||||
type describeRequest struct {
|
||||
sh *searchHandler
|
||||
sh *Handler
|
||||
|
||||
lk sync.Mutex // protects m
|
||||
m map[string]interface{} // top-level response JSON
|
||||
|
@ -246,7 +246,7 @@ func (dr *describeRequest) describeReally(br *blobref.BlobRef, depth int) {
|
|||
}
|
||||
}
|
||||
|
||||
func (sh *searchHandler) serveDescribe(rw http.ResponseWriter, req *http.Request) {
|
||||
func (sh *Handler) serveDescribe(rw http.ResponseWriter, req *http.Request) {
|
||||
ret := jsonMap()
|
||||
defer httputil.ReturnJson(rw, ret)
|
||||
|
||||
|
@ -262,7 +262,7 @@ func (sh *searchHandler) serveDescribe(rw http.ResponseWriter, req *http.Request
|
|||
dr.wg.Wait()
|
||||
}
|
||||
|
||||
func (sh *searchHandler) serveFiles(rw http.ResponseWriter, req *http.Request) {
|
||||
func (sh *Handler) serveFiles(rw http.ResponseWriter, req *http.Request) {
|
||||
ret := jsonMap()
|
||||
defer httputil.ReturnJson(rw, ret)
|
||||
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html"
|
||||
"http"
|
||||
"os"
|
||||
|
||||
"camli/blobserver"
|
||||
"camli/jsonconfig"
|
||||
"camli/search"
|
||||
)
|
||||
|
||||
// PublishHandler publishes your info to the world, if permanodes have
|
||||
// appropriate ACLs set. (everything is private by default)
|
||||
type PublishHandler struct {
|
||||
Search *search.Handler
|
||||
Storage blobserver.Storage // of blobRoot
|
||||
Cache blobserver.Storage // or nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
blobserver.RegisterHandlerConstructor("publish", newPublishFromConfig)
|
||||
}
|
||||
|
||||
func newPublishFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (h http.Handler, err os.Error) {
|
||||
pub := &PublishHandler{}
|
||||
blobRoot := conf.RequiredString("blobRoot")
|
||||
searchRoot := conf.RequiredString("searchRoot")
|
||||
cachePrefix := conf.OptionalString("cache", "")
|
||||
if err = conf.Validate(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
bs, err := ld.GetStorage(blobRoot)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("publish handler's blobRoot of %q error: %v", blobRoot, err)
|
||||
}
|
||||
pub.Storage = bs
|
||||
|
||||
si, err := ld.GetHandler(searchRoot)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("publish handler's searchRoot of %q error: %v", searchRoot, err)
|
||||
}
|
||||
pub.Search = si.(*search.Handler)
|
||||
|
||||
if cachePrefix != "" {
|
||||
bs, err := ld.GetStorage(cachePrefix)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("publish handler's cache of %q error: %v", cachePrefix, err)
|
||||
}
|
||||
pub.Cache = bs
|
||||
}
|
||||
|
||||
return pub, nil
|
||||
}
|
||||
|
||||
func (pub *PublishHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||
base := req.Header.Get("X-PrefixHandler-PathBase")
|
||||
suffix := req.Header.Get("X-PrefixHandler-PathSuffix")
|
||||
|
||||
fmt.Fprintf(rw, "I am publish handler at base %q, suffix %q", base, html.EscapeString(suffix))
|
||||
}
|
|
@ -117,7 +117,7 @@ func newUiFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (h http.Handler,
|
|||
if cachePrefix != "" {
|
||||
bs, err := ld.GetStorage(cachePrefix)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("UI handler's cache of %q error: %v", ui.BlobRoot, err)
|
||||
return nil, fmt.Errorf("UI handler's cache of %q error: %v", cachePrefix, err)
|
||||
}
|
||||
ui.Cache = bs
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue