download token: also render JSON

This commit is contained in:
Mikaël Cluseau
2025-07-22 11:58:18 +02:00
parent d4087d3534
commit cef4441208
2 changed files with 21 additions and 3 deletions

View File

@ -8,6 +8,7 @@ import (
"log"
"net/http"
"strconv"
"strings"
"time"
restful "github.com/emicklei/go-restful"
@ -55,7 +56,7 @@ func wsAuthorizeDownload(req *restful.Request, resp *restful.Response) {
resp.WriteAsJson(token)
}
func wsDownload(req *restful.Request, resp *restful.Response) {
func wsDownloadAsset(req *restful.Request, resp *restful.Response) {
token := req.PathParameter("token")
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) {
token := req.PathParameter("token")