mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-02-28 05:55:37 +08:00
路径规则、重写规则、URL跳转规则均支持匹配条件;URL跳转规则增加排序、是否启用功能
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
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/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"regexp"
|
||||
"strings"
|
||||
@@ -28,6 +30,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
this.Data["type"] = locationConfig.PatternType()
|
||||
this.Data["isReverse"] = locationConfig.IsReverse()
|
||||
this.Data["isCaseInsensitive"] = locationConfig.IsCaseInsensitive()
|
||||
this.Data["conds"] = locationConfig.Conds
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -45,6 +48,8 @@ func (this *IndexAction) RunPost(params struct {
|
||||
IsReverse bool
|
||||
IsOn bool
|
||||
|
||||
CondsJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
defer this.CreateLogInfo("修改路径规则 %d 设置", params.LocationId)
|
||||
@@ -67,6 +72,20 @@ func (this *IndexAction) RunPost(params struct {
|
||||
params.Pattern = "/" + strings.TrimLeft(params.Pattern, "/")
|
||||
}
|
||||
|
||||
// 校验匹配条件
|
||||
if len(params.CondsJSON) > 0 {
|
||||
conds := &shared.HTTPRequestCondsConfig{}
|
||||
err := json.Unmarshal(params.CondsJSON, conds)
|
||||
if err != nil {
|
||||
this.Fail("匹配条件校验失败:" + err.Error())
|
||||
}
|
||||
|
||||
err = conds.Init()
|
||||
if err != nil {
|
||||
this.Fail("匹配条件校验失败:" + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
location := &serverconfigs.HTTPLocationConfig{}
|
||||
location.SetPattern(params.Pattern, params.PatternType, params.IsCaseInsensitive, params.IsReverse)
|
||||
resultPattern := location.Pattern
|
||||
@@ -78,6 +97,7 @@ func (this *IndexAction) RunPost(params struct {
|
||||
Pattern: resultPattern,
|
||||
IsBreak: params.IsBreak,
|
||||
IsOn: params.IsOn,
|
||||
CondsJSON: params.CondsJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
Reference in New Issue
Block a user