自定义页面增加例外URL和限制URL设置

This commit is contained in:
刘祥超
2023-11-13 10:45:13 +08:00
parent 5fd6a08988
commit 4a74488cac
8 changed files with 192 additions and 49 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"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"
)
@@ -29,12 +30,18 @@ func (this *UpdatePopupAction) RunGet(params struct {
return
}
pageConfig := &serverconfigs.HTTPPageConfig{}
var pageConfig = &serverconfigs.HTTPPageConfig{}
err = json.Unmarshal(configResp.PageJSON, pageConfig)
if err != nil {
this.ErrorPage(err)
return
}
if pageConfig.ExceptURLPatterns == nil {
pageConfig.ExceptURLPatterns = []*shared.URLPattern{}
}
if pageConfig.OnlyURLPatterns == nil {
pageConfig.OnlyURLPatterns = []*shared.URLPattern{}
}
this.Data["pageConfig"] = pageConfig
this.Show()
@@ -49,6 +56,9 @@ func (this *UpdatePopupAction) RunPost(params struct {
URL string `alias:"url"`
Body string
ExceptURLPatternsJSON []byte
OnlyURLPatternsJSON []byte
NewStatus int
Must *actions.Must
@@ -60,6 +70,11 @@ func (this *UpdatePopupAction) RunPost(params struct {
Field("status", params.Status).
Require("请输入响应状态码")
if len(params.Status) != 3 {
this.FailField("status", "状态码长度必须为3位")
return
}
switch params.BodyType {
case serverconfigs.HTTPPageBodyTypeURL:
params.Must.
@@ -82,13 +97,33 @@ func (this *UpdatePopupAction) RunPost(params struct {
}
}
var exceptURLPatterns = []*shared.URLPattern{}
if len(params.ExceptURLPatternsJSON) > 0 {
err := json.Unmarshal(params.ExceptURLPatternsJSON, &exceptURLPatterns)
if err != nil {
this.ErrorPage(err)
return
}
}
var onlyURLPatterns = []*shared.URLPattern{}
if len(params.OnlyURLPatternsJSON) > 0 {
err := json.Unmarshal(params.OnlyURLPatternsJSON, &onlyURLPatterns)
if err != nil {
this.ErrorPage(err)
return
}
}
_, err := this.RPC().HTTPPageRPC().UpdateHTTPPage(this.AdminContext(), &pb.UpdateHTTPPageRequest{
HttpPageId: params.PageId,
StatusList: []string{params.Status},
BodyType: params.BodyType,
Url: params.URL,
Body: params.Body,
NewStatus: types.Int32(params.NewStatus),
HttpPageId: params.PageId,
StatusList: []string{params.Status},
BodyType: params.BodyType,
Url: params.URL,
Body: params.Body,
NewStatus: types.Int32(params.NewStatus),
ExceptURLPatternsJSON: params.ExceptURLPatternsJSON,
OnlyURLPatternsJSON: params.OnlyURLPatternsJSON,
})
if err != nil {
this.ErrorPage(err)