feature: download set

This commit is contained in:
Mikaël Cluseau
2025-07-22 18:54:48 +02:00
parent cef4441208
commit 5fa367949b
6 changed files with 317 additions and 10 deletions

View File

@ -105,6 +105,10 @@ func wsDownloadAsset(req *restful.Request, resp *restful.Response) {
log.Printf("download via token: %s %q asset %q", spec.Kind, spec.Name, asset)
downloadAsset(req, resp, spec.Kind, spec.Name, asset)
}
func downloadAsset(req *restful.Request, resp *restful.Response, kind, name, asset string) {
cfg, err := readConfig()
if err != nil {
wsError(resp, err)
@ -112,12 +116,12 @@ func wsDownloadAsset(req *restful.Request, resp *restful.Response) {
}
setHeader := func(ext string) {
resp.AddHeader("Content-Disposition", "attachment; filename="+strconv.Quote(spec.Kind+"_"+spec.Name+"_"+asset+ext))
resp.AddHeader("Content-Disposition", "attachment; filename="+strconv.Quote(kind+"_"+name+"_"+asset+ext))
}
switch spec.Kind {
switch kind {
case "cluster":
cluster := cfg.ClusterByName(spec.Name)
cluster := cfg.ClusterByName(name)
if cluster == nil {
wsNotFound(resp)
return
@ -133,7 +137,7 @@ func wsDownloadAsset(req *restful.Request, resp *restful.Response) {
}
case "host":
host := hostOrTemplate(cfg, spec.Name)
host := hostOrTemplate(cfg, name)
if host == nil {
wsNotFound(resp)
return