mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-03-13 23:55:36 +08:00
路径规则、重写规则、URL跳转规则均支持匹配条件;URL跳转规则增加排序、是否启用功能
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
|
||||
"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"
|
||||
@@ -48,6 +49,7 @@ func (this *CreateAction) RunPost(params struct {
|
||||
IsBreak bool
|
||||
IsCaseInsensitive bool
|
||||
IsReverse bool
|
||||
CondsJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
@@ -63,6 +65,20 @@ func (this *CreateAction) RunPost(params struct {
|
||||
}
|
||||
}
|
||||
|
||||
// 校验匹配条件
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
// 自动加上前缀斜杠
|
||||
if params.PatternType == serverconfigs.HTTPLocationPatternTypePrefix ||
|
||||
params.PatternType == serverconfigs.HTTPLocationPatternTypeExact {
|
||||
@@ -79,6 +95,7 @@ func (this *CreateAction) RunPost(params struct {
|
||||
Description: params.Description,
|
||||
Pattern: resultPattern,
|
||||
IsBreak: params.IsBreak,
|
||||
CondsJSON: params.CondsJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package redirects
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"net/url"
|
||||
@@ -30,8 +32,9 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
MatchPrefix bool
|
||||
MatchRegexp bool
|
||||
KeepRequestURI bool
|
||||
|
||||
Status int
|
||||
Status int
|
||||
CondsJSON []byte
|
||||
IsOn bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
@@ -80,6 +83,21 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
Field("status", params.Status).
|
||||
Gte(0, "请选择正确的跳转状态码")
|
||||
|
||||
// 校验匹配条件
|
||||
var conds *shared.HTTPRequestCondsConfig
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
this.Data["redirect"] = maps.Map{
|
||||
"status": params.Status,
|
||||
"beforeURL": params.BeforeURL,
|
||||
@@ -87,7 +105,8 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
"matchPrefix": params.MatchPrefix,
|
||||
"matchRegexp": params.MatchRegexp,
|
||||
"keepRequestURI": params.KeepRequestURI,
|
||||
"isOn": true,
|
||||
"conds": conds,
|
||||
"isOn": params.IsOn,
|
||||
}
|
||||
|
||||
this.Success()
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
|
||||
"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"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"regexp"
|
||||
@@ -37,6 +38,8 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
IsBreak bool
|
||||
IsOn bool
|
||||
|
||||
CondsJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
params.Must.
|
||||
@@ -54,6 +57,20 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
Field("replace", params.Replace).
|
||||
Require("请输入目标URL")
|
||||
|
||||
// 校验匹配条件
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
// web配置
|
||||
webConfig, err := dao.SharedHTTPWebDAO.FindWebConfigWithId(this.AdminContext(), params.WebId)
|
||||
if err != nil {
|
||||
@@ -71,6 +88,7 @@ func (this *CreatePopupAction) RunPost(params struct {
|
||||
WithQuery: params.WithQuery,
|
||||
IsBreak: params.IsBreak,
|
||||
IsOn: params.IsOn,
|
||||
CondsJSON: params.CondsJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package rewrite
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"regexp"
|
||||
@@ -56,6 +58,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
WithQuery bool
|
||||
IsBreak bool
|
||||
IsOn bool
|
||||
CondsJSON []byte
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
@@ -76,6 +79,20 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
Field("replace", params.Replace).
|
||||
Require("请输入目标URL")
|
||||
|
||||
// 校验匹配条件
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
// 修改
|
||||
_, err := this.RPC().HTTPRewriteRuleRPC().UpdateHTTPRewriteRule(this.AdminContext(), &pb.UpdateHTTPRewriteRuleRequest{
|
||||
RewriteRuleId: params.RewriteRuleId,
|
||||
@@ -87,6 +104,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
WithQuery: params.WithQuery,
|
||||
IsBreak: params.IsBreak,
|
||||
IsOn: params.IsOn,
|
||||
CondsJSON: params.CondsJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
|
||||
Reference in New Issue
Block a user