2020-09-29 11:28:39 +08:00
|
|
|
package conds
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
|
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/conds/condutils"
|
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
|
|
|
|
"github.com/iwind/TeaGo/actions"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type AddCondPopupAction struct {
|
|
|
|
|
actionutils.ParentAction
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *AddCondPopupAction) Init() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *AddCondPopupAction) RunGet(params struct{}) {
|
|
|
|
|
this.Data["components"] = condutils.ReadAllAvailableCondTypes()
|
|
|
|
|
|
|
|
|
|
this.Show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *AddCondPopupAction) RunPost(params struct {
|
|
|
|
|
CondType string
|
|
|
|
|
CondJSON []byte
|
|
|
|
|
|
|
|
|
|
Must *actions.Must
|
|
|
|
|
}) {
|
|
|
|
|
condConfig := &shared.HTTPRequestCond{}
|
|
|
|
|
err := json.Unmarshal(params.CondJSON, condConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.Fail("解析条件设置时发生了错误:" + err.Error())
|
|
|
|
|
}
|
2021-06-08 22:46:08 +08:00
|
|
|
err = condConfig.Init()
|
|
|
|
|
if err != nil {
|
|
|
|
|
this.Fail("校验条件设置时失败:" + err.Error())
|
|
|
|
|
}
|
2020-09-29 11:28:39 +08:00
|
|
|
condConfig.Type = params.CondType
|
|
|
|
|
|
|
|
|
|
this.Data["cond"] = condConfig
|
|
|
|
|
this.Success()
|
|
|
|
|
}
|