mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2026-01-04 22:35:48 +08:00
特殊页面可以直接使用HTML
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"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, statusList []string, url string, newStatus int) (pageId int64, err error) {
|
||||
func (this *HTTPPageDAO) CreatePage(tx *dbs.Tx, statusList []string, bodyType shared.BodyType, url string, body string, newStatus int) (pageId int64, err error) {
|
||||
op := NewHTTPPageOperator()
|
||||
op.IsOn = true
|
||||
op.State = HTTPPageStateEnabled
|
||||
@@ -88,7 +89,9 @@ func (this *HTTPPageDAO) CreatePage(tx *dbs.Tx, statusList []string, url string,
|
||||
}
|
||||
op.StatusList = string(statusListJSON)
|
||||
}
|
||||
op.BodyType = bodyType
|
||||
op.Url = url
|
||||
op.Body = body
|
||||
op.NewStatus = newStatus
|
||||
err = this.Save(tx, op)
|
||||
if err != nil {
|
||||
@@ -99,7 +102,7 @@ func (this *HTTPPageDAO) CreatePage(tx *dbs.Tx, statusList []string, url string,
|
||||
}
|
||||
|
||||
// UpdatePage 修改Page
|
||||
func (this *HTTPPageDAO) UpdatePage(tx *dbs.Tx, pageId int64, statusList []string, url string, newStatus int) error {
|
||||
func (this *HTTPPageDAO) UpdatePage(tx *dbs.Tx, pageId int64, statusList []string, bodyType shared.BodyType, url string, body string, newStatus int) error {
|
||||
if pageId <= 0 {
|
||||
return errors.New("invalid pageId")
|
||||
}
|
||||
@@ -118,7 +121,9 @@ func (this *HTTPPageDAO) UpdatePage(tx *dbs.Tx, pageId int64, statusList []strin
|
||||
}
|
||||
op.StatusList = string(statusListJSON)
|
||||
|
||||
op.BodyType = bodyType
|
||||
op.Url = url
|
||||
op.Body = body
|
||||
op.NewStatus = newStatus
|
||||
err = this.Save(tx, op)
|
||||
if err != nil {
|
||||
@@ -152,6 +157,12 @@ func (this *HTTPPageDAO) ComposePageConfig(tx *dbs.Tx, pageId int64, cacheMap ma
|
||||
config.IsOn = page.IsOn == 1
|
||||
config.NewStatus = int(page.NewStatus)
|
||||
config.URL = page.Url
|
||||
config.Body = page.Body
|
||||
config.BodyType = page.BodyType
|
||||
|
||||
if len(page.BodyType) == 0 {
|
||||
page.BodyType = shared.BodyTypeURL
|
||||
}
|
||||
|
||||
if len(page.StatusList) > 0 {
|
||||
statusList := []string{}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package models
|
||||
|
||||
//
|
||||
// HTTPPage 特殊页面
|
||||
type HTTPPage struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
@@ -11,6 +11,8 @@ type HTTPPage struct {
|
||||
NewStatus int32 `field:"newStatus"` // 新状态码
|
||||
State uint8 `field:"state"` // 状态
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
Body string `field:"body"` // 页面内容
|
||||
BodyType string `field:"bodyType"` // 内容类型
|
||||
}
|
||||
|
||||
type HTTPPageOperator struct {
|
||||
@@ -23,6 +25,8 @@ type HTTPPageOperator struct {
|
||||
NewStatus interface{} // 新状态码
|
||||
State interface{} // 状态
|
||||
CreatedAt interface{} // 创建时间
|
||||
Body interface{} // 页面内容
|
||||
BodyType interface{} // 内容类型
|
||||
}
|
||||
|
||||
func NewHTTPPageOperator() *HTTPPageOperator {
|
||||
|
||||
@@ -22,7 +22,7 @@ func (this *HTTPPageService) CreateHTTPPage(ctx context.Context, req *pb.CreateH
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
pageId, err := models.SharedHTTPPageDAO.CreatePage(tx, req.StatusList, req.Url, types.Int(req.NewStatus))
|
||||
pageId, err := models.SharedHTTPPageDAO.CreatePage(tx, req.StatusList, req.BodyType, req.Url, req.Body, types.Int(req.NewStatus))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func (this *HTTPPageService) UpdateHTTPPage(ctx context.Context, req *pb.UpdateH
|
||||
|
||||
tx := this.NullTx()
|
||||
|
||||
err = models.SharedHTTPPageDAO.UpdatePage(tx, req.PageId, req.StatusList, req.Url, types.Int(req.NewStatus))
|
||||
err = models.SharedHTTPPageDAO.UpdatePage(tx, req.PageId, req.StatusList, req.BodyType, req.Url, req.Body, types.Int(req.NewStatus))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user