mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-07 18:50:26 +08:00
自定义页面增加“跳转URL”功能
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
@@ -77,7 +76,7 @@ func (this *HTTPPageDAO) FindEnabledHTTPPage(tx *dbs.Tx, id int64) (*HTTPPage, e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreatePage 创建Page
|
// CreatePage 创建Page
|
||||||
func (this *HTTPPageDAO) CreatePage(tx *dbs.Tx, userId int64, statusList []string, bodyType shared.BodyType, 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) (pageId int64, err error) {
|
||||||
var op = NewHTTPPageOperator()
|
var op = NewHTTPPageOperator()
|
||||||
op.UserId = userId
|
op.UserId = userId
|
||||||
op.IsOn = true
|
op.IsOn = true
|
||||||
@@ -103,7 +102,7 @@ func (this *HTTPPageDAO) CreatePage(tx *dbs.Tx, userId int64, statusList []strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UpdatePage 修改Page
|
// UpdatePage 修改Page
|
||||||
func (this *HTTPPageDAO) UpdatePage(tx *dbs.Tx, pageId int64, statusList []string, bodyType shared.BodyType, 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) error {
|
||||||
if pageId <= 0 {
|
if pageId <= 0 {
|
||||||
return errors.New("invalid pageId")
|
return errors.New("invalid pageId")
|
||||||
}
|
}
|
||||||
@@ -188,7 +187,7 @@ func (this *HTTPPageDAO) ComposePageConfig(tx *dbs.Tx, pageId int64, cacheMap *u
|
|||||||
config.BodyType = page.BodyType
|
config.BodyType = page.BodyType
|
||||||
|
|
||||||
if len(page.BodyType) == 0 {
|
if len(page.BodyType) == 0 {
|
||||||
page.BodyType = shared.BodyTypeURL
|
page.BodyType = serverconfigs.HTTPPageBodyTypeURL
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(page.StatusList) > 0 {
|
if len(page.StatusList) > 0 {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||||
"github.com/TeaOSLab/EdgeAPI/internal/utils/regexputils"
|
"github.com/TeaOSLab/EdgeAPI/internal/utils/regexputils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ func (this *HTTPPageService) CreateHTTPPage(ctx context.Context, req *pb.CreateH
|
|||||||
const maxBodyLength = 32 * 1024
|
const maxBodyLength = 32 * 1024
|
||||||
|
|
||||||
switch req.BodyType {
|
switch req.BodyType {
|
||||||
case shared.BodyTypeURL:
|
case serverconfigs.HTTPPageBodyTypeURL:
|
||||||
if len(req.Url) > maxURLLength {
|
if len(req.Url) > maxURLLength {
|
||||||
return nil, errors.New("'url' too long")
|
return nil, errors.New("'url' too long")
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,18 @@ func (this *HTTPPageService) CreateHTTPPage(ctx context.Context, req *pb.CreateH
|
|||||||
if len(req.Body) > maxBodyLength { // we keep short body for user experience
|
if len(req.Body) > maxBodyLength { // we keep short body for user experience
|
||||||
req.Body = ""
|
req.Body = ""
|
||||||
}
|
}
|
||||||
case shared.BodyTypeHTML:
|
case serverconfigs.HTTPPageBodyTypeRedirectURL:
|
||||||
|
if len(req.Url) > maxURLLength {
|
||||||
|
return nil, errors.New("'url' too long")
|
||||||
|
}
|
||||||
|
if !regexputils.HTTPProtocol.MatchString(req.Url) {
|
||||||
|
return nil, errors.New("invalid 'url' format")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(req.Body) > maxBodyLength { // we keep short body for user experience
|
||||||
|
req.Body = ""
|
||||||
|
}
|
||||||
|
case serverconfigs.HTTPPageBodyTypeHTML:
|
||||||
if len(req.Body) > maxBodyLength {
|
if len(req.Body) > maxBodyLength {
|
||||||
return nil, errors.New("'body' too long")
|
return nil, errors.New("'body' too long")
|
||||||
}
|
}
|
||||||
@@ -82,7 +93,7 @@ func (this *HTTPPageService) UpdateHTTPPage(ctx context.Context, req *pb.UpdateH
|
|||||||
const maxBodyLength = 32 * 1024
|
const maxBodyLength = 32 * 1024
|
||||||
|
|
||||||
switch req.BodyType {
|
switch req.BodyType {
|
||||||
case shared.BodyTypeURL:
|
case serverconfigs.HTTPPageBodyTypeURL:
|
||||||
if len(req.Url) > maxURLLength {
|
if len(req.Url) > maxURLLength {
|
||||||
return nil, errors.New("'url' too long")
|
return nil, errors.New("'url' too long")
|
||||||
}
|
}
|
||||||
@@ -93,7 +104,18 @@ func (this *HTTPPageService) UpdateHTTPPage(ctx context.Context, req *pb.UpdateH
|
|||||||
if len(req.Body) > maxBodyLength { // we keep short body for user experience
|
if len(req.Body) > maxBodyLength { // we keep short body for user experience
|
||||||
req.Body = ""
|
req.Body = ""
|
||||||
}
|
}
|
||||||
case shared.BodyTypeHTML:
|
case serverconfigs.HTTPPageBodyTypeRedirectURL:
|
||||||
|
if len(req.Url) > maxURLLength {
|
||||||
|
return nil, errors.New("'url' too long")
|
||||||
|
}
|
||||||
|
if !regexputils.HTTPProtocol.MatchString(req.Url) {
|
||||||
|
return nil, errors.New("invalid 'url' format")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(req.Body) > maxBodyLength { // we keep short body for user experience
|
||||||
|
req.Body = ""
|
||||||
|
}
|
||||||
|
case serverconfigs.HTTPPageBodyTypeHTML:
|
||||||
if len(req.Body) > maxBodyLength {
|
if len(req.Body) > maxBodyLength {
|
||||||
return nil, errors.New("'body' too long")
|
return nil, errors.New("'body' too long")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeAPI/internal/utils/regexputils"
|
"github.com/TeaOSLab/EdgeAPI/internal/utils/regexputils"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -365,7 +364,7 @@ func (this *HTTPWebService) UpdateHTTPWebShutdown(ctx context.Context, req *pb.U
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch shutdownConfig.BodyType {
|
switch shutdownConfig.BodyType {
|
||||||
case shared.BodyTypeURL:
|
case serverconfigs.HTTPPageBodyTypeURL:
|
||||||
if len(shutdownConfig.URL) > maxURLLength {
|
if len(shutdownConfig.URL) > maxURLLength {
|
||||||
return nil, errors.New("'url' too long")
|
return nil, errors.New("'url' too long")
|
||||||
}
|
}
|
||||||
@@ -376,7 +375,18 @@ func (this *HTTPWebService) UpdateHTTPWebShutdown(ctx context.Context, req *pb.U
|
|||||||
if len(shutdownConfig.Body) > maxBodyLength { // we keep short body for user experience
|
if len(shutdownConfig.Body) > maxBodyLength { // we keep short body for user experience
|
||||||
shutdownConfig.Body = ""
|
shutdownConfig.Body = ""
|
||||||
}
|
}
|
||||||
case shared.BodyTypeHTML:
|
case serverconfigs.HTTPPageBodyTypeRedirectURL:
|
||||||
|
if len(shutdownConfig.URL) > maxURLLength {
|
||||||
|
return nil, errors.New("'url' too long")
|
||||||
|
}
|
||||||
|
if shutdownConfig.IsOn /** validate when it's on **/ && !regexputils.HTTPProtocol.MatchString(shutdownConfig.URL) {
|
||||||
|
return nil, errors.New("invalid 'url' format")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(shutdownConfig.Body) > maxBodyLength { // we keep short body for user experience
|
||||||
|
shutdownConfig.Body = ""
|
||||||
|
}
|
||||||
|
case serverconfigs.HTTPPageBodyTypeHTML:
|
||||||
if len(shutdownConfig.Body) > maxBodyLength {
|
if len(shutdownConfig.Body) > maxBodyLength {
|
||||||
return nil, errors.New("'body' too long")
|
return nil, errors.New("'body' too long")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user