mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-30 09:56:35 +08:00
自定义页面增加例外URL和限制URL设置
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
@@ -76,7 +77,7 @@ func (this *HTTPPageDAO) FindEnabledHTTPPage(tx *dbs.Tx, id int64) (*HTTPPage, e
|
||||
}
|
||||
|
||||
// CreatePage 创建Page
|
||||
func (this *HTTPPageDAO) CreatePage(tx *dbs.Tx, userId int64, statusList []string, bodyType serverconfigs.HTTPPageBodyType, url string, body string, newStatus int) (pageId int64, err error) {
|
||||
func (this *HTTPPageDAO) CreatePage(tx *dbs.Tx, userId int64, statusList []string, bodyType serverconfigs.HTTPPageBodyType, url string, body string, newStatus int, exceptURLPatterns []*shared.URLPattern, onlyURLPatterns []*shared.URLPattern) (pageId int64, err error) {
|
||||
var op = NewHTTPPageOperator()
|
||||
op.UserId = userId
|
||||
op.IsOn = true
|
||||
@@ -93,6 +94,29 @@ func (this *HTTPPageDAO) CreatePage(tx *dbs.Tx, userId int64, statusList []strin
|
||||
op.Url = url
|
||||
op.Body = body
|
||||
op.NewStatus = newStatus
|
||||
|
||||
{
|
||||
if exceptURLPatterns == nil {
|
||||
exceptURLPatterns = []*shared.URLPattern{}
|
||||
}
|
||||
exceptURLPatternsJSON, err := json.Marshal(exceptURLPatterns)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
op.ExceptURLPatterns = exceptURLPatternsJSON
|
||||
}
|
||||
|
||||
{
|
||||
if onlyURLPatterns == nil {
|
||||
onlyURLPatterns = []*shared.URLPattern{}
|
||||
}
|
||||
onlyURLPatternsJSON, err := json.Marshal(onlyURLPatterns)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
op.OnlyURLPatterns = onlyURLPatternsJSON
|
||||
}
|
||||
|
||||
err = this.Save(tx, op)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -102,7 +126,7 @@ func (this *HTTPPageDAO) CreatePage(tx *dbs.Tx, userId int64, statusList []strin
|
||||
}
|
||||
|
||||
// UpdatePage 修改Page
|
||||
func (this *HTTPPageDAO) UpdatePage(tx *dbs.Tx, pageId int64, statusList []string, bodyType serverconfigs.HTTPPageBodyType, url string, body string, newStatus int) error {
|
||||
func (this *HTTPPageDAO) UpdatePage(tx *dbs.Tx, pageId int64, statusList []string, bodyType serverconfigs.HTTPPageBodyType, url string, body string, newStatus int, exceptURLPatterns []*shared.URLPattern, onlyURLPatterns []*shared.URLPattern) error {
|
||||
if pageId <= 0 {
|
||||
return errors.New("invalid pageId")
|
||||
}
|
||||
@@ -125,6 +149,29 @@ func (this *HTTPPageDAO) UpdatePage(tx *dbs.Tx, pageId int64, statusList []strin
|
||||
op.Url = url
|
||||
op.Body = body
|
||||
op.NewStatus = newStatus
|
||||
|
||||
{
|
||||
if exceptURLPatterns == nil {
|
||||
exceptURLPatterns = []*shared.URLPattern{}
|
||||
}
|
||||
exceptURLPatternsJSON, err := json.Marshal(exceptURLPatterns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
op.ExceptURLPatterns = exceptURLPatternsJSON
|
||||
}
|
||||
|
||||
{
|
||||
if onlyURLPatterns == nil {
|
||||
onlyURLPatterns = []*shared.URLPattern{}
|
||||
}
|
||||
onlyURLPatternsJSON, err := json.Marshal(onlyURLPatterns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
op.OnlyURLPatterns = onlyURLPatternsJSON
|
||||
}
|
||||
|
||||
err = this.Save(tx, op)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -155,6 +202,14 @@ func (this *HTTPPageDAO) ClonePage(tx *dbs.Tx, fromPageId int64) (newPageId int6
|
||||
op.Body = page.Body
|
||||
op.BodyType = page.BodyType
|
||||
op.State = page.State
|
||||
|
||||
if len(page.ExceptURLPatterns) > 0 {
|
||||
op.ExceptURLPatterns = page.ExceptURLPatterns
|
||||
}
|
||||
if len(page.OnlyURLPatterns) > 0 {
|
||||
op.OnlyURLPatterns = page.OnlyURLPatterns
|
||||
}
|
||||
|
||||
return this.SaveInt64(tx, op)
|
||||
}
|
||||
|
||||
@@ -178,7 +233,7 @@ func (this *HTTPPageDAO) ComposePageConfig(tx *dbs.Tx, pageId int64, cacheMap *u
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
config := &serverconfigs.HTTPPageConfig{}
|
||||
var config = &serverconfigs.HTTPPageConfig{}
|
||||
config.Id = int64(page.Id)
|
||||
config.IsOn = page.IsOn
|
||||
config.NewStatus = int(page.NewStatus)
|
||||
@@ -201,6 +256,28 @@ func (this *HTTPPageDAO) ComposePageConfig(tx *dbs.Tx, pageId int64, cacheMap *u
|
||||
}
|
||||
}
|
||||
|
||||
if len(page.ExceptURLPatterns) > 0 {
|
||||
var exceptURLPatterns = []*shared.URLPattern{}
|
||||
err = json.Unmarshal(page.ExceptURLPatterns, &exceptURLPatterns)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(exceptURLPatterns) > 0 {
|
||||
config.ExceptURLPatterns = exceptURLPatterns
|
||||
}
|
||||
}
|
||||
|
||||
if len(page.OnlyURLPatterns) > 0 {
|
||||
var onlyURLPatterns = []*shared.URLPattern{}
|
||||
err = json.Unmarshal(page.OnlyURLPatterns, &onlyURLPatterns)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(onlyURLPatterns) > 0 {
|
||||
config.OnlyURLPatterns = onlyURLPatterns
|
||||
}
|
||||
}
|
||||
|
||||
if cacheMap != nil {
|
||||
cacheMap.Put(cacheKey, config)
|
||||
}
|
||||
|
||||
@@ -2,33 +2,53 @@ package models
|
||||
|
||||
import "github.com/iwind/TeaGo/dbs"
|
||||
|
||||
const (
|
||||
HTTPPageField_Id dbs.FieldName = "id" // ID
|
||||
HTTPPageField_AdminId dbs.FieldName = "adminId" // 管理员ID
|
||||
HTTPPageField_UserId dbs.FieldName = "userId" // 用户ID
|
||||
HTTPPageField_IsOn dbs.FieldName = "isOn" // 是否启用
|
||||
HTTPPageField_StatusList dbs.FieldName = "statusList" // 状态列表
|
||||
HTTPPageField_Url dbs.FieldName = "url" // 页面URL
|
||||
HTTPPageField_NewStatus dbs.FieldName = "newStatus" // 新状态码
|
||||
HTTPPageField_State dbs.FieldName = "state" // 状态
|
||||
HTTPPageField_CreatedAt dbs.FieldName = "createdAt" // 创建时间
|
||||
HTTPPageField_Body dbs.FieldName = "body" // 页面内容
|
||||
HTTPPageField_BodyType dbs.FieldName = "bodyType" // 内容类型
|
||||
HTTPPageField_ExceptURLPatterns dbs.FieldName = "exceptURLPatterns" // 例外URL
|
||||
HTTPPageField_OnlyURLPatterns dbs.FieldName = "onlyURLPatterns" // 限制URL
|
||||
)
|
||||
|
||||
// HTTPPage 特殊页面
|
||||
type HTTPPage struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
UserId uint32 `field:"userId"` // 用户ID
|
||||
IsOn bool `field:"isOn"` // 是否启用
|
||||
StatusList dbs.JSON `field:"statusList"` // 状态列表
|
||||
Url string `field:"url"` // 页面URL
|
||||
NewStatus int32 `field:"newStatus"` // 新状态码
|
||||
State uint8 `field:"state"` // 状态
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
Body string `field:"body"` // 页面内容
|
||||
BodyType string `field:"bodyType"` // 内容类型
|
||||
Id uint32 `field:"id"` // ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
UserId uint32 `field:"userId"` // 用户ID
|
||||
IsOn bool `field:"isOn"` // 是否启用
|
||||
StatusList dbs.JSON `field:"statusList"` // 状态列表
|
||||
Url string `field:"url"` // 页面URL
|
||||
NewStatus int32 `field:"newStatus"` // 新状态码
|
||||
State uint8 `field:"state"` // 状态
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
Body string `field:"body"` // 页面内容
|
||||
BodyType string `field:"bodyType"` // 内容类型
|
||||
ExceptURLPatterns dbs.JSON `field:"exceptURLPatterns"` // 例外URL
|
||||
OnlyURLPatterns dbs.JSON `field:"onlyURLPatterns"` // 限制URL
|
||||
}
|
||||
|
||||
type HTTPPageOperator struct {
|
||||
Id interface{} // ID
|
||||
AdminId interface{} // 管理员ID
|
||||
UserId interface{} // 用户ID
|
||||
IsOn interface{} // 是否启用
|
||||
StatusList interface{} // 状态列表
|
||||
Url interface{} // 页面URL
|
||||
NewStatus interface{} // 新状态码
|
||||
State interface{} // 状态
|
||||
CreatedAt interface{} // 创建时间
|
||||
Body interface{} // 页面内容
|
||||
BodyType interface{} // 内容类型
|
||||
Id any // ID
|
||||
AdminId any // 管理员ID
|
||||
UserId any // 用户ID
|
||||
IsOn any // 是否启用
|
||||
StatusList any // 状态列表
|
||||
Url any // 页面URL
|
||||
NewStatus any // 新状态码
|
||||
State any // 状态
|
||||
CreatedAt any // 创建时间
|
||||
Body any // 页面内容
|
||||
BodyType any // 内容类型
|
||||
ExceptURLPatterns any // 例外URL
|
||||
OnlyURLPatterns any // 限制URL
|
||||
}
|
||||
|
||||
func NewHTTPPageOperator() *HTTPPageOperator {
|
||||
|
||||
Reference in New Issue
Block a user