mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-01-29 05:15:50 +08:00
实现路径规则各项数据修改
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user