mirror of https://github.com/perkeep/perkeep.git
Add support for downloading an assembled blob via the share URL.
Bug: https://code.google.com/p/camlistore/issues/detail?id=220 Change-Id: I4604105d2679010d6f546692abbce0d57bae2983
This commit is contained in:
parent
f0a00be32b
commit
544d901840
|
@ -24,6 +24,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -54,6 +55,9 @@ func newShareFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (h http.Handl
|
||||||
if blobRoot == "" {
|
if blobRoot == "" {
|
||||||
return nil, errors.New("No blobRoot defined for share handler")
|
return nil, errors.New("No blobRoot defined for share handler")
|
||||||
}
|
}
|
||||||
|
if err = conf.Validate(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
share := &shareHandler{
|
share := &shareHandler{
|
||||||
blobRoot: blobRoot,
|
blobRoot: blobRoot,
|
||||||
|
@ -171,13 +175,23 @@ func handleGetViaSharing(conn http.ResponseWriter, req *http.Request,
|
||||||
|
|
||||||
viaPathOkay = true
|
viaPathOkay = true
|
||||||
|
|
||||||
|
if assemble, _ := strconv.ParseBool(req.FormValue("assemble")); assemble {
|
||||||
|
dh := &DownloadHandler{
|
||||||
|
Fetcher: fetcher,
|
||||||
|
// TODO(aa): It would be nice to specify a local cache here, as the UI handler does.
|
||||||
|
}
|
||||||
|
dh.ServeHTTP(conn, req, blobRef)
|
||||||
|
} else {
|
||||||
gethandler.ServeBlobRef(conn, req, blobRef, fetcher)
|
gethandler.ServeBlobRef(conn, req, blobRef, fetcher)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *shareHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
func (h *shareHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
||||||
blobRef, ok := blob.Parse(httputil.PathSuffix(req))
|
pathSuffix := httputil.PathSuffix(req)
|
||||||
|
pathParts := strings.SplitN(pathSuffix, "/", 2)
|
||||||
|
blobRef, ok := blob.Parse(pathParts[0])
|
||||||
if !ok {
|
if !ok {
|
||||||
http.Error(rw, "Malformed share URL.", 400)
|
http.Error(rw, fmt.Sprintf("Malformed share pathSuffix: %s", pathSuffix), 400)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
handleGetViaSharing(rw, req, blobRef, h.fetcher)
|
handleGetViaSharing(rw, req, blobRef, h.fetcher)
|
||||||
|
|
Loading…
Reference in New Issue