Files
EdgeAdmin/internal/web/actions/default/servers/components/waf/exportDownload.go

40 lines
919 B
Go
Raw Normal View History

2020-12-02 16:09:23 +08:00
package waf
import (
"github.com/TeaOSLab/EdgeAdmin/internal/ttlcache"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/types"
2020-12-02 16:09:23 +08:00
"strconv"
)
type ExportDownloadAction struct {
actionutils.ParentAction
}
func (this *ExportDownloadAction) Init() {
this.Nav("", "", "")
}
func (this *ExportDownloadAction) RunGet(params struct {
Key string
PolicyId int64
2020-12-02 16:09:23 +08:00
}) {
item := ttlcache.DefaultCache.Read(params.Key)
if item == nil || item.Value == nil {
this.WriteString("找不到要导出的内容")
return
}
ttlcache.DefaultCache.Delete(params.Key)
data, ok := item.Value.([]byte)
if ok {
this.AddHeader("Content-Disposition", "attachment; filename=\"WAF-"+types.String(params.PolicyId)+".json\";")
2020-12-02 16:09:23 +08:00
this.AddHeader("Content-Length", strconv.Itoa(len(data)))
2023-08-08 14:17:16 +08:00
_, _ = this.Write(data)
2020-12-02 16:09:23 +08:00
} else {
this.WriteString("找不到要导出的内容")
return
}
}