实现路径规则各项数据修改

This commit is contained in:
GoEdgeLab
2020-09-22 11:36:51 +08:00
parent c126d06f70
commit 41bddd79c9
110 changed files with 1799 additions and 182 deletions

View File

@@ -1,10 +1,12 @@
package location
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
"regexp"
"strings"
)
// 路径规则详情
@@ -13,26 +15,70 @@ type IndexAction struct {
}
func (this *IndexAction) Init() {
this.TinyMenu("basic")
}
func (this *IndexAction) RunGet(params struct {
LocationId int64
}) {
locationConfigResp, err := this.RPC().HTTPLocationRPC().FindEnabledHTTPLocationConfig(this.AdminContext(), &pb.FindEnabledHTTPLocationConfigRequest{LocationId: params.LocationId})
if err != nil {
this.ErrorPage(err)
return
}
locationConfig := &serverconfigs.HTTPLocationConfig{}
err = json.Unmarshal(locationConfigResp.LocationJSON, locationConfig)
if err != nil {
this.ErrorPage(err)
return
}
locationConfig := this.Data.Get("locationConfig").(*serverconfigs.HTTPLocationConfig)
this.Data["locationId"] = locationConfig.Id
this.Data["locationConfig"] = locationConfig
this.Data["patternTypes"] = serverconfigs.AllLocationPatternTypes()
this.Data["pattern"] = locationConfig.PatternString()
this.Data["type"] = locationConfig.PatternType()
this.Data["isReverse"] = locationConfig.IsReverse()
this.Data["isCaseInsensitive"] = locationConfig.IsCaseInsensitive()
this.Show()
}
func (this *IndexAction) RunPost(params struct {
LocationId int64
Name string
Pattern string
PatternType int
Description string
IsBreak bool
IsCaseInsensitive bool
IsReverse bool
Must *actions.Must
}) {
params.Must.
Field("pattern", params.Pattern).
Require("请输入路径匹配规则")
// 校验正则
if params.PatternType == serverconfigs.HTTPLocationPatternTypeRegexp {
_, err := regexp.Compile(params.Pattern)
if err != nil {
this.Fail("正则表达式校验失败:" + err.Error())
}
}
// 自动加上前缀斜杠
if params.PatternType == serverconfigs.HTTPLocationPatternTypePrefix ||
params.PatternType == serverconfigs.HTTPLocationPatternTypeExact {
params.Pattern = "/" + strings.TrimLeft(params.Pattern, "/")
}
location := &serverconfigs.HTTPLocationConfig{}
location.SetPattern(params.Pattern, params.PatternType, params.IsCaseInsensitive, params.IsReverse)
resultPattern := location.Pattern
_, err := this.RPC().HTTPLocationRPC().UpdateHTTPLocation(this.AdminContext(), &pb.UpdateHTTPLocationRequest{
LocationId: params.LocationId,
Name: params.Name,
Description: params.Description,
Pattern: resultPattern,
IsBreak: params.IsBreak,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -13,6 +13,7 @@ func init() {
Helper(helpers.NewUserMustAuth()).
Helper(locationutils.NewLocationHelper()).
Helper(serverutils.NewServerHelper()).
Data("tinyMenuItem", "basic").
Prefix("/servers/server/settings/locations/location").
GetPost("", new(IndexAction)).
EndAll()