Files
EdgeAdmin/internal/web/actions/default/servers/server/settings/cache/createPopup.go

62 lines
1.2 KiB
Go
Raw Normal View History

2020-10-04 20:38:27 +08:00
package cache
import (
"encoding/json"
2022-03-04 17:00:01 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/utils"
2020-10-04 20:38:27 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
)
type CreatePopupAction struct {
actionutils.ParentAction
}
func (this *CreatePopupAction) Init() {
this.Nav("", "", "")
}
func (this *CreatePopupAction) RunGet(params struct {
IsReverse bool
}) {
this.Data["isReverse"] = params.IsReverse
2020-10-04 20:38:27 +08:00
this.Show()
}
func (this *CreatePopupAction) RunPost(params struct {
CacheRefJSON []byte
2020-10-04 20:38:27 +08:00
Must *actions.Must
}) {
2022-03-04 17:00:01 +08:00
var cacheRef = &serverconfigs.HTTPCacheRef{}
err := json.Unmarshal(params.CacheRefJSON, cacheRef)
2020-10-04 20:38:27 +08:00
if err != nil {
this.ErrorPage(err)
return
}
if len(cacheRef.Key) == 0 {
this.Fail("请输入缓存Key")
}
if cacheRef.Conds == nil || len(cacheRef.Conds.Groups) == 0 {
this.Fail("请填写匹配条件分组")
}
2022-03-04 17:00:01 +08:00
this.Data["cacheRef"] = cacheRef
cacheRefClone, err := utils.JSONClone(cacheRef)
if err != nil {
this.Fail(err.Error())
}
err = cacheRefClone.(*serverconfigs.HTTPCacheRef).Init()
2020-10-04 20:38:27 +08:00
if err != nil {
this.ErrorPage(err)
return
}
this.Data["cacheRef"] = cacheRef
this.Success()
}