download token: also render JSON
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
restful "github.com/emicklei/go-restful"
|
restful "github.com/emicklei/go-restful"
|
||||||
@ -55,7 +56,7 @@ func wsAuthorizeDownload(req *restful.Request, resp *restful.Response) {
|
|||||||
resp.WriteAsJson(token)
|
resp.WriteAsJson(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
func wsDownload(req *restful.Request, resp *restful.Response) {
|
func wsDownloadAsset(req *restful.Request, resp *restful.Response) {
|
||||||
token := req.PathParameter("token")
|
token := req.PathParameter("token")
|
||||||
asset := req.PathParameter("asset")
|
asset := req.PathParameter("asset")
|
||||||
|
|
||||||
@ -152,6 +153,23 @@ func wsDownload(req *restful.Request, resp *restful.Response) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func wsDownload(req *restful.Request, resp *restful.Response) {
|
||||||
|
if strings.HasSuffix(req.Request.URL.Path, "/") {
|
||||||
|
wsDownloadPage(req, resp)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
token := req.PathParameter("token")
|
||||||
|
|
||||||
|
spec, ok := wState.Get().Downloads[token]
|
||||||
|
if !ok {
|
||||||
|
wsNotFound(resp)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resp.WriteEntity(spec)
|
||||||
|
}
|
||||||
|
|
||||||
func wsDownloadPage(req *restful.Request, resp *restful.Response) {
|
func wsDownloadPage(req *restful.Request, resp *restful.Response) {
|
||||||
token := req.PathParameter("token")
|
token := req.PathParameter("token")
|
||||||
|
|
||||||
|
@ -37,8 +37,8 @@ func registerWS(rest *restful.Container) {
|
|||||||
Route(ws.POST("/store.tar").To(wsStoreUpload).
|
Route(ws.POST("/store.tar").To(wsStoreUpload).
|
||||||
Consumes(mime.TAR).
|
Consumes(mime.TAR).
|
||||||
Doc("Upload an existing store")).
|
Doc("Upload an existing store")).
|
||||||
Route(ws.GET("/downloads/{token}/").To(wsDownloadPage)).
|
Route(ws.GET("/downloads/{token}").To(wsDownload)).
|
||||||
Route(ws.GET("/downloads/{token}/{asset}").To(wsDownload).
|
Route(ws.GET("/downloads/{token}/{asset}").To(wsDownloadAsset).
|
||||||
Param(ws.PathParameter("token", "the download token")).
|
Param(ws.PathParameter("token", "the download token")).
|
||||||
Param(ws.PathParameter("asset", "the requested asset")).
|
Param(ws.PathParameter("asset", "the requested asset")).
|
||||||
Doc("Fetch an asset via a download token"))
|
Doc("Fetch an asset via a download token"))
|
||||||
|
Reference in New Issue
Block a user