mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	简化代码/增加HTTPPage服务
This commit is contained in:
		@@ -64,6 +64,7 @@ func (this *APINode) listenRPC() error {
 | 
			
		||||
	pb.RegisterHTTPGzipServiceServer(rpcServer, &services.HTTPGzipService{})
 | 
			
		||||
	pb.RegisterHTTPHeaderPolicyServiceServer(rpcServer, &services.HTTPHeaderPolicyService{})
 | 
			
		||||
	pb.RegisterHTTPHeaderServiceServer(rpcServer, &services.HTTPHeaderService{})
 | 
			
		||||
	pb.RegisterHTTPPageServiceServer(rpcServer, &services.HTTPPageService{})
 | 
			
		||||
	err = rpcServer.Serve(listener)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return errors.New("[API]start rpc failed: " + err.Error())
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										144
									
								
								internal/db/models/http_page_dao.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										144
									
								
								internal/db/models/http_page_dao.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,144 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
 | 
			
		||||
	_ "github.com/go-sql-driver/mysql"
 | 
			
		||||
	"github.com/iwind/TeaGo/Tea"
 | 
			
		||||
	"github.com/iwind/TeaGo/dbs"
 | 
			
		||||
	"github.com/iwind/TeaGo/types"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	HTTPPageStateEnabled  = 1 // 已启用
 | 
			
		||||
	HTTPPageStateDisabled = 0 // 已禁用
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type HTTPPageDAO dbs.DAO
 | 
			
		||||
 | 
			
		||||
func NewHTTPPageDAO() *HTTPPageDAO {
 | 
			
		||||
	return dbs.NewDAO(&HTTPPageDAO{
 | 
			
		||||
		DAOObject: dbs.DAOObject{
 | 
			
		||||
			DB:     Tea.Env,
 | 
			
		||||
			Table:  "edgeHTTPPages",
 | 
			
		||||
			Model:  new(HTTPPage),
 | 
			
		||||
			PkName: "id",
 | 
			
		||||
		},
 | 
			
		||||
	}).(*HTTPPageDAO)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var SharedHTTPPageDAO = NewHTTPPageDAO()
 | 
			
		||||
 | 
			
		||||
// 启用条目
 | 
			
		||||
func (this *HTTPPageDAO) EnableHTTPPage(id int64) error {
 | 
			
		||||
	_, err := this.Query().
 | 
			
		||||
		Pk(id).
 | 
			
		||||
		Set("state", HTTPPageStateEnabled).
 | 
			
		||||
		Update()
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 禁用条目
 | 
			
		||||
func (this *HTTPPageDAO) DisableHTTPPage(id int64) error {
 | 
			
		||||
	_, err := this.Query().
 | 
			
		||||
		Pk(id).
 | 
			
		||||
		Set("state", HTTPPageStateDisabled).
 | 
			
		||||
		Update()
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找启用中的条目
 | 
			
		||||
func (this *HTTPPageDAO) FindEnabledHTTPPage(id int64) (*HTTPPage, error) {
 | 
			
		||||
	result, err := this.Query().
 | 
			
		||||
		Pk(id).
 | 
			
		||||
		Attr("state", HTTPPageStateEnabled).
 | 
			
		||||
		Find()
 | 
			
		||||
	if result == nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return result.(*HTTPPage), err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 创建Page
 | 
			
		||||
func (this *HTTPPageDAO) CreatePage(statusList []string, url string, newStatus int) (pageId int64, err error) {
 | 
			
		||||
	op := NewHTTPPageOperator()
 | 
			
		||||
	op.IsOn = true
 | 
			
		||||
	op.State = HTTPPageStateEnabled
 | 
			
		||||
 | 
			
		||||
	if len(statusList) > 0 {
 | 
			
		||||
		statusListJSON, err := json.Marshal(statusList)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return 0, err
 | 
			
		||||
		}
 | 
			
		||||
		op.StatusList = string(statusListJSON)
 | 
			
		||||
	}
 | 
			
		||||
	op.Url = url
 | 
			
		||||
	op.NewStatus = newStatus
 | 
			
		||||
	_, err = this.Save(op)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return 0, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return types.Int64(op.Id), nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改Page
 | 
			
		||||
func (this *HTTPPageDAO) UpdatePage(pageId int64, statusList []string, url string, newStatus int) error {
 | 
			
		||||
	if pageId <= 0 {
 | 
			
		||||
		return errors.New("invalid pageId")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	op := NewHTTPPageOperator()
 | 
			
		||||
	op.Id = pageId
 | 
			
		||||
	op.IsOn = true
 | 
			
		||||
	op.State = HTTPPageStateEnabled
 | 
			
		||||
 | 
			
		||||
	if statusList == nil {
 | 
			
		||||
		statusList = []string{}
 | 
			
		||||
	}
 | 
			
		||||
	statusListJSON, err := json.Marshal(statusList)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	op.StatusList = string(statusListJSON)
 | 
			
		||||
 | 
			
		||||
	op.Url = url
 | 
			
		||||
	op.NewStatus = newStatus
 | 
			
		||||
	_, err = this.Save(op)
 | 
			
		||||
 | 
			
		||||
	// TODO 修改相关引用的对象
 | 
			
		||||
 | 
			
		||||
	return err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 组合配置
 | 
			
		||||
func (this *HTTPPageDAO) ComposePageConfig(pageId int64) (*serverconfigs.HTTPPageConfig, error) {
 | 
			
		||||
	page, err := this.FindEnabledHTTPPage(pageId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if page == nil {
 | 
			
		||||
		return nil, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	config := &serverconfigs.HTTPPageConfig{}
 | 
			
		||||
	config.Id = int64(page.Id)
 | 
			
		||||
	config.IsOn = page.IsOn == 1
 | 
			
		||||
	config.NewStatus = int(page.NewStatus)
 | 
			
		||||
	config.URL = page.Url
 | 
			
		||||
 | 
			
		||||
	if len(page.StatusList) > 0 {
 | 
			
		||||
		statusList := []string{}
 | 
			
		||||
		err = json.Unmarshal([]byte(page.StatusList), &statusList)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		if len(statusList) > 0 {
 | 
			
		||||
			config.Status = statusList
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return config, nil
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										5
									
								
								internal/db/models/http_page_dao_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								internal/db/models/http_page_dao_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	_ "github.com/go-sql-driver/mysql"
 | 
			
		||||
)
 | 
			
		||||
							
								
								
									
										30
									
								
								internal/db/models/http_page_model.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								internal/db/models/http_page_model.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
type HTTPPage struct {
 | 
			
		||||
	Id         uint32 `field:"id"`         // ID
 | 
			
		||||
	AdminId    uint32 `field:"adminId"`    // 管理员ID
 | 
			
		||||
	UserId     uint32 `field:"userId"`     // 用户ID
 | 
			
		||||
	IsOn       uint8  `field:"isOn"`       // 是否启用
 | 
			
		||||
	StatusList string `field:"statusList"` // 状态列表
 | 
			
		||||
	Url        string `field:"url"`        // 页面URL
 | 
			
		||||
	NewStatus  int32  `field:"newStatus"`  // 新状态码
 | 
			
		||||
	State      uint8  `field:"state"`      // 状态
 | 
			
		||||
	CreatedAt  uint32 `field:"createdAt"`  // 创建时间
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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{} // 创建时间
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewHTTPPageOperator() *HTTPPageOperator {
 | 
			
		||||
	return &HTTPPageOperator{}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1
									
								
								internal/db/models/http_page_model_ext.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								internal/db/models/http_page_model_ext.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
package models
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
 | 
			
		||||
	_ "github.com/go-sql-driver/mysql"
 | 
			
		||||
@@ -106,6 +107,35 @@ func (this *HTTPWebDAO) ComposeWebConfig(webId int64) (*serverconfigs.HTTPWebCon
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// shutdown
 | 
			
		||||
	if IsNotNull(web.Shutdown) {
 | 
			
		||||
		shutdownConfig := &serverconfigs.HTTPShutdownConfig{}
 | 
			
		||||
		err = json.Unmarshal([]byte(web.Shutdown), shutdownConfig)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		config.Shutdown = shutdownConfig
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// pages
 | 
			
		||||
	if IsNotNull(web.Pages) {
 | 
			
		||||
		pages := []*serverconfigs.HTTPPageConfig{}
 | 
			
		||||
		err = json.Unmarshal([]byte(web.Pages), &pages)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
		for index, page := range pages {
 | 
			
		||||
			pageConfig, err := SharedHTTPPageDAO.ComposePageConfig(page.Id)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return nil, err
 | 
			
		||||
			}
 | 
			
		||||
			pages[index] = pageConfig
 | 
			
		||||
		}
 | 
			
		||||
		if len(pages) > 0 {
 | 
			
		||||
			config.Pages = pages
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// TODO 更多配置
 | 
			
		||||
 | 
			
		||||
	return config, nil
 | 
			
		||||
@@ -172,7 +202,7 @@ func (this *HTTPWebDAO) UpdateWebCharset(webId int64, charset string) error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 更改请求Header策略
 | 
			
		||||
func (this *HTTPWebDAO) UpdateHTTPWebRequestHeaderPolicy(webId int64, headerPolicyId int64) error {
 | 
			
		||||
func (this *HTTPWebDAO) UpdateWebRequestHeaderPolicy(webId int64, headerPolicyId int64) error {
 | 
			
		||||
	if webId <= 0 {
 | 
			
		||||
		return errors.New("invalid webId")
 | 
			
		||||
	}
 | 
			
		||||
@@ -188,7 +218,7 @@ func (this *HTTPWebDAO) UpdateHTTPWebRequestHeaderPolicy(webId int64, headerPoli
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 更改响应Header策略
 | 
			
		||||
func (this *HTTPWebDAO) UpdateHTTPWebResponseHeaderPolicy(webId int64, headerPolicyId int64) error {
 | 
			
		||||
func (this *HTTPWebDAO) UpdateWebResponseHeaderPolicy(webId int64, headerPolicyId int64) error {
 | 
			
		||||
	if webId <= 0 {
 | 
			
		||||
		return errors.New("invalid webId")
 | 
			
		||||
	}
 | 
			
		||||
@@ -203,6 +233,38 @@ func (this *HTTPWebDAO) UpdateHTTPWebResponseHeaderPolicy(webId int64, headerPol
 | 
			
		||||
	return this.NotifyUpdating(webId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 更改特殊页面配置
 | 
			
		||||
func (this *HTTPWebDAO) UpdateWebPages(webId int64, pagesJSON []byte) error {
 | 
			
		||||
	if webId <= 0 {
 | 
			
		||||
		return errors.New("invalid webId")
 | 
			
		||||
	}
 | 
			
		||||
	op := NewHTTPWebOperator()
 | 
			
		||||
	op.Id = webId
 | 
			
		||||
	op.Pages = JSONBytes(pagesJSON)
 | 
			
		||||
	_, err := this.Save(op)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return this.NotifyUpdating(webId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 更改Shutdown配置
 | 
			
		||||
func (this *HTTPWebDAO) UpdateWebShutdown(webId int64, shutdownJSON []byte) error {
 | 
			
		||||
	if webId <= 0 {
 | 
			
		||||
		return errors.New("invalid webId")
 | 
			
		||||
	}
 | 
			
		||||
	op := NewHTTPWebOperator()
 | 
			
		||||
	op.Id = webId
 | 
			
		||||
	op.Shutdown = JSONBytes(shutdownJSON)
 | 
			
		||||
	_, err := this.Save(op)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return this.NotifyUpdating(webId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 通知更新
 | 
			
		||||
func (this *HTTPWebDAO) NotifyUpdating(webId int64) error {
 | 
			
		||||
	err := SharedServerDAO.UpdateServerIsUpdatingWithWebId(webId)
 | 
			
		||||
 
 | 
			
		||||
@@ -2,4 +2,23 @@ package models
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	_ "github.com/go-sql-driver/mysql"
 | 
			
		||||
	"testing"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestHTTPWebDAO_UpdateWebShutdown(t *testing.T) {
 | 
			
		||||
	{
 | 
			
		||||
		err := SharedHTTPWebDAO.UpdateWebShutdown(1, []byte("{}"))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			t.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	{
 | 
			
		||||
		err := SharedHTTPWebDAO.UpdateWebShutdown(1, nil)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			t.Fatal(err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	t.Log("ok")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										14
									
								
								internal/db/models/utils.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								internal/db/models/utils.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,14 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
// 处理JSON字节Slice
 | 
			
		||||
func JSONBytes(data []byte) []byte {
 | 
			
		||||
	if len(data) == 0 {
 | 
			
		||||
		return []byte("null")
 | 
			
		||||
	}
 | 
			
		||||
	return data
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 判断JSON是否为空
 | 
			
		||||
func IsNotNull(data string) bool {
 | 
			
		||||
	return len(data) > 0 && data != "null"
 | 
			
		||||
}
 | 
			
		||||
@@ -26,7 +26,7 @@ func (this *APINodeService) CreateAPINode(ctx context.Context, req *pb.CreateAPI
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改API节点
 | 
			
		||||
func (this *APINodeService) UpdateAPINode(ctx context.Context, req *pb.UpdateAPINodeRequest) (*pb.UpdateAPINodeResponse, error) {
 | 
			
		||||
func (this *APINodeService) UpdateAPINode(ctx context.Context, req *pb.UpdateAPINodeRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -37,7 +37,7 @@ func (this *APINodeService) UpdateAPINode(ctx context.Context, req *pb.UpdateAPI
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateAPINodeResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 删除API节点
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,7 @@ func (this *HTTPHeaderService) CreateHTTPHeader(ctx context.Context, req *pb.Cre
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改Header
 | 
			
		||||
func (this *HTTPHeaderService) UpdateHTTPHeader(ctx context.Context, req *pb.UpdateHTTPHeaderRequest) (*pb.UpdateHTTPHeaderResponse, error) {
 | 
			
		||||
func (this *HTTPHeaderService) UpdateHTTPHeader(ctx context.Context, req *pb.UpdateHTTPHeaderRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -38,7 +38,7 @@ func (this *HTTPHeaderService) UpdateHTTPHeader(ctx context.Context, req *pb.Upd
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateHTTPHeaderResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找配置
 | 
			
		||||
 
 | 
			
		||||
@@ -47,7 +47,7 @@ func (this *HTTPHeaderPolicyService) CreateHTTPHeaderPolicy(ctx context.Context,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改AddHeaders
 | 
			
		||||
func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyAddingHeaders(ctx context.Context, req *pb.UpdateHTTPHeaderPolicyAddingHeadersRequest) (*pb.UpdateHTTPHeaderPolicyAddingHeadersResponse, error) {
 | 
			
		||||
func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyAddingHeaders(ctx context.Context, req *pb.UpdateHTTPHeaderPolicyAddingHeadersRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -58,11 +58,11 @@ func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyAddingHeaders(ctx con
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateHTTPHeaderPolicyAddingHeadersResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改SetHeaders
 | 
			
		||||
func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicySettingHeaders(ctx context.Context, req *pb.UpdateHTTPHeaderPolicySettingHeadersRequest) (*pb.UpdateHTTPHeaderPolicySettingHeadersResponse, error) {
 | 
			
		||||
func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicySettingHeaders(ctx context.Context, req *pb.UpdateHTTPHeaderPolicySettingHeadersRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -73,11 +73,11 @@ func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicySettingHeaders(ctx co
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateHTTPHeaderPolicySettingHeadersResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改AddTrailers
 | 
			
		||||
func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyAddingTrailers(ctx context.Context, req *pb.UpdateHTTPHeaderPolicyAddingTrailersRequest) (*pb.UpdateHTTPHeaderPolicyAddingTrailersResponse, error) {
 | 
			
		||||
func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyAddingTrailers(ctx context.Context, req *pb.UpdateHTTPHeaderPolicyAddingTrailersRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -88,11 +88,11 @@ func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyAddingTrailers(ctx co
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateHTTPHeaderPolicyAddingTrailersResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改ReplaceHeaders
 | 
			
		||||
func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyReplacingHeaders(ctx context.Context, req *pb.UpdateHTTPHeaderPolicyReplacingHeadersRequest) (*pb.UpdateHTTPHeaderPolicyReplacingHeadersResponse, error) {
 | 
			
		||||
func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyReplacingHeaders(ctx context.Context, req *pb.UpdateHTTPHeaderPolicyReplacingHeadersRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -103,11 +103,11 @@ func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyReplacingHeaders(ctx
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateHTTPHeaderPolicyReplacingHeadersResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改删除的Headers
 | 
			
		||||
func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyDeletingHeaders(ctx context.Context, req *pb.UpdateHTTPHeaderPolicyDeletingHeadersRequest) (*pb.UpdateHTTPHeaderPolicyDeletingHeadersResponse, error) {
 | 
			
		||||
func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyDeletingHeaders(ctx context.Context, req *pb.UpdateHTTPHeaderPolicyDeletingHeadersRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -118,5 +118,5 @@ func (this *HTTPHeaderPolicyService) UpdateHTTPHeaderPolicyDeletingHeaders(ctx c
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateHTTPHeaderPolicyDeletingHeadersResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										67
									
								
								internal/rpc/services/service_http_page.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								internal/rpc/services/service_http_page.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,67 @@
 | 
			
		||||
package services
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/db/models"
 | 
			
		||||
	rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/iwind/TeaGo/types"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type HTTPPageService struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 创建Page
 | 
			
		||||
func (this *HTTPPageService) CreateHTTPPage(ctx context.Context, req *pb.CreateHTTPPageRequest) (*pb.CreateHTTPPageResponse, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	pageId, err := models.SharedHTTPPageDAO.CreatePage(req.StatusList, req.Url, types.Int(req.NewStatus))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.CreateHTTPPageResponse{PageId: pageId}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改Page
 | 
			
		||||
func (this *HTTPPageService) UpdateHTTPPage(ctx context.Context, req *pb.UpdateHTTPPageRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = models.SharedHTTPPageDAO.UpdatePage(req.PageId, req.StatusList, req.Url, types.Int(req.NewStatus))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return rpcutils.RPCUpdateSuccess()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找单个Page配置
 | 
			
		||||
func (this *HTTPPageService) FindEnabledHTTPPageConfig(ctx context.Context, req *pb.FindEnabledHTTPPageConfigRequest) (*pb.FindEnabledHTTPPageConfigResponse, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	config, err := models.SharedHTTPPageDAO.ComposePageConfig(req.PageId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	configJSON, err := json.Marshal(config)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.FindEnabledHTTPPageConfigResponse{
 | 
			
		||||
		Config: configJSON,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
@@ -55,7 +55,7 @@ func (this *HTTPWebService) FindEnabledHTTPWeb(ctx context.Context, req *pb.Find
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改Web配置
 | 
			
		||||
func (this *HTTPWebService) UpdateHTTPWeb(ctx context.Context, req *pb.UpdateHTTPWebRequest) (*pb.UpdateHTTPWebResponse, error) {
 | 
			
		||||
func (this *HTTPWebService) UpdateHTTPWeb(ctx context.Context, req *pb.UpdateHTTPWebRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -67,11 +67,11 @@ func (this *HTTPWebService) UpdateHTTPWeb(ctx context.Context, req *pb.UpdateHTT
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateHTTPWebResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改Gzip配置
 | 
			
		||||
func (this *HTTPWebService) UpdateHTTPWebGzip(ctx context.Context, req *pb.UpdateHTTPWebGzipRequest) (*pb.UpdateHTTPWebGzipResponse, error) {
 | 
			
		||||
func (this *HTTPWebService) UpdateHTTPWebGzip(ctx context.Context, req *pb.UpdateHTTPWebGzipRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -83,11 +83,11 @@ func (this *HTTPWebService) UpdateHTTPWebGzip(ctx context.Context, req *pb.Updat
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateHTTPWebGzipResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改字符集配置
 | 
			
		||||
func (this *HTTPWebService) UpdateHTTPWebCharset(ctx context.Context, req *pb.UpdateHTTPWebCharsetRequest) (*pb.UpdateHTTPWebCharsetResponse, error) {
 | 
			
		||||
func (this *HTTPWebService) UpdateHTTPWebCharset(ctx context.Context, req *pb.UpdateHTTPWebCharsetRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -98,38 +98,67 @@ func (this *HTTPWebService) UpdateHTTPWebCharset(ctx context.Context, req *pb.Up
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return &pb.UpdateHTTPWebCharsetResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 更改请求Header策略
 | 
			
		||||
func (this *HTTPWebService) UpdateHTTPWebRequestHeaderPolicy(ctx context.Context, req *pb.UpdateHTTPWebRequestHeaderPolicyRequest) (*pb.UpdateHTTPWebRequestHeaderPolicyResponse, error) {
 | 
			
		||||
func (this *HTTPWebService) UpdateHTTPWebRequestHeaderPolicy(ctx context.Context, req *pb.UpdateHTTPWebRequestHeaderPolicyRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = models.SharedHTTPWebDAO.UpdateHTTPWebRequestHeaderPolicy(req.WebId, req.HeaderPolicyId)
 | 
			
		||||
	err = models.SharedHTTPWebDAO.UpdateWebRequestHeaderPolicy(req.WebId, req.HeaderPolicyId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateHTTPWebRequestHeaderPolicyResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 更改响应Header策略
 | 
			
		||||
func (this *HTTPWebService) UpdateHTTPWebResponseHeaderPolicy(ctx context.Context, req *pb.UpdateHTTPWebResponseHeaderPolicyRequest) (*pb.UpdateHTTPWebResponseHeaderPolicyResponse, error) {
 | 
			
		||||
func (this *HTTPWebService) UpdateHTTPWebResponseHeaderPolicy(ctx context.Context, req *pb.UpdateHTTPWebResponseHeaderPolicyRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = models.SharedHTTPWebDAO.UpdateHTTPWebResponseHeaderPolicy(req.WebId, req.HeaderPolicyId)
 | 
			
		||||
	err = models.SharedHTTPWebDAO.UpdateWebResponseHeaderPolicy(req.WebId, req.HeaderPolicyId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateHTTPWebResponseHeaderPolicyResponse{}, nil
 | 
			
		||||
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 更改Shutdown
 | 
			
		||||
func (this *HTTPWebService) UpdateHTTPWebShutdown(ctx context.Context, req *pb.UpdateHTTPWebShutdownRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = models.SharedHTTPWebDAO.UpdateWebShutdown(req.WebId, req.ShutdownJSON)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return rpcutils.RPCUpdateSuccess()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 更改Pages
 | 
			
		||||
func (this *HTTPWebService) UpdateHTTPWebPages(ctx context.Context, req *pb.UpdateHTTPWebPagesRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = models.SharedHTTPWebDAO.UpdateWebPages(req.WebId, req.PagesJSON)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return rpcutils.RPCUpdateSuccess()
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -137,7 +137,7 @@ func (this *NodeService) DisableNode(ctx context.Context, req *pb.DisableNodeReq
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改节点
 | 
			
		||||
func (this *NodeService) UpdateNode(ctx context.Context, req *pb.UpdateNodeRequest) (*pb.UpdateNodeResponse, error) {
 | 
			
		||||
func (this *NodeService) UpdateNode(ctx context.Context, req *pb.UpdateNodeRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -167,7 +167,7 @@ func (this *NodeService) UpdateNode(ctx context.Context, req *pb.UpdateNodeReque
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateNodeResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 列出单个节点
 | 
			
		||||
@@ -311,7 +311,7 @@ func (this *NodeService) NodeStream(server pb.NodeService_NodeStreamServer) erro
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 更新节点状态
 | 
			
		||||
func (this *NodeService) UpdateNodeStatus(ctx context.Context, req *pb.UpdateNodeStatusRequest) (*pb.UpdateNodeStatusResponse, error) {
 | 
			
		||||
func (this *NodeService) UpdateNodeStatus(ctx context.Context, req *pb.UpdateNodeStatusRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	// 校验节点
 | 
			
		||||
	_, nodeId, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeNode)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -331,7 +331,7 @@ func (this *NodeService) UpdateNodeStatus(ctx context.Context, req *pb.UpdateNod
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateNodeStatusResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 同步集群中的节点版本
 | 
			
		||||
@@ -350,7 +350,7 @@ func (this *NodeService) SyncNodesVersionWithCluster(ctx context.Context, req *p
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改节点安装状态
 | 
			
		||||
func (this *NodeService) UpdateNodeIsInstalled(ctx context.Context, req *pb.UpdateNodeIsInstalledRequest) (*pb.UpdateNodeIsInstalledResponse, error) {
 | 
			
		||||
func (this *NodeService) UpdateNodeIsInstalled(ctx context.Context, req *pb.UpdateNodeIsInstalledRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -361,7 +361,7 @@ func (this *NodeService) UpdateNodeIsInstalled(ctx context.Context, req *pb.Upda
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateNodeIsInstalledResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 安装节点
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,7 @@ func (this *NodeClusterService) CreateNodeCluster(ctx context.Context, req *pb.C
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改集群
 | 
			
		||||
func (this *NodeClusterService) UpdateNodeCluster(ctx context.Context, req *pb.UpdateNodeClusterRequest) (*pb.UpdateNodeClusterResponse, error) {
 | 
			
		||||
func (this *NodeClusterService) UpdateNodeCluster(ctx context.Context, req *pb.UpdateNodeClusterRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -37,7 +37,7 @@ func (this *NodeClusterService) UpdateNodeCluster(ctx context.Context, req *pb.U
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateNodeClusterResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 禁用集群
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,7 @@ func (this *NodeGrantService) CreateNodeGrant(ctx context.Context, req *pb.Creat
 | 
			
		||||
	}, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *NodeGrantService) UpdateNodeGrant(ctx context.Context, req *pb.UpdateNodeGrantRequest) (*pb.UpdateNodeGrantResponse, error) {
 | 
			
		||||
func (this *NodeGrantService) UpdateNodeGrant(ctx context.Context, req *pb.UpdateNodeGrantRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -37,7 +37,7 @@ func (this *NodeGrantService) UpdateNodeGrant(ctx context.Context, req *pb.Updat
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err = models.SharedNodeGrantDAO.UpdateGrant(req.GrantId, req.Name, req.Method, req.Username, req.Password, req.PrivateKey, req.Description, req.NodeId)
 | 
			
		||||
	return &pb.UpdateNodeGrantResponse{}, err
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *NodeGrantService) DisableNodeGrant(ctx context.Context, req *pb.DisableNodeGrantRequest) (*pb.DisableNodeGrantResponse, error) {
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,7 @@ func (this *NodeIPAddressService) CreateNodeIPAddress(ctx context.Context, req *
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改IP地址
 | 
			
		||||
func (this *NodeIPAddressService) UpdateNodeIPAddress(ctx context.Context, req *pb.UpdateNodeIPAddressRequest) (*pb.UpdateNodeIPAddressResponse, error) {
 | 
			
		||||
func (this *NodeIPAddressService) UpdateNodeIPAddress(ctx context.Context, req *pb.UpdateNodeIPAddressRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -39,11 +39,11 @@ func (this *NodeIPAddressService) UpdateNodeIPAddress(ctx context.Context, req *
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateNodeIPAddressResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改IP地址所属节点
 | 
			
		||||
func (this *NodeIPAddressService) UpdateNodeIPAddressNodeId(ctx context.Context, req *pb.UpdateNodeIPAddressNodeIdRequest) (*pb.UpdateNodeIPAddressNodeIdResponse, error) {
 | 
			
		||||
func (this *NodeIPAddressService) UpdateNodeIPAddressNodeId(ctx context.Context, req *pb.UpdateNodeIPAddressNodeIdRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -55,7 +55,7 @@ func (this *NodeIPAddressService) UpdateNodeIPAddressNodeId(ctx context.Context,
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateNodeIPAddressNodeIdResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 禁用单个IP地址
 | 
			
		||||
 
 | 
			
		||||
@@ -38,7 +38,7 @@ func (this *OriginServerService) CreateOriginServer(ctx context.Context, req *pb
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改源站
 | 
			
		||||
func (this *OriginServerService) UpdateOriginServer(ctx context.Context, req *pb.UpdateOriginServerRequest) (*pb.UpdateOriginServerResponse, error) {
 | 
			
		||||
func (this *OriginServerService) UpdateOriginServer(ctx context.Context, req *pb.UpdateOriginServerRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -57,7 +57,7 @@ func (this *OriginServerService) UpdateOriginServer(ctx context.Context, req *pb
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateOriginServerResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 查找单个源站信息
 | 
			
		||||
 
 | 
			
		||||
@@ -74,7 +74,7 @@ func (this *ReverseProxyService) FindEnabledReverseProxyConfig(ctx context.Conte
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改反向代理调度算法
 | 
			
		||||
func (this *ReverseProxyService) UpdateReverseProxyScheduling(ctx context.Context, req *pb.UpdateReverseProxySchedulingRequest) (*pb.UpdateReverseProxySchedulingResponse, error) {
 | 
			
		||||
func (this *ReverseProxyService) UpdateReverseProxyScheduling(ctx context.Context, req *pb.UpdateReverseProxySchedulingRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -86,11 +86,11 @@ func (this *ReverseProxyService) UpdateReverseProxyScheduling(ctx context.Contex
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateReverseProxySchedulingResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改主要源站信息
 | 
			
		||||
func (this *ReverseProxyService) UpdateReverseProxyPrimaryOrigins(ctx context.Context, req *pb.UpdateReverseProxyPrimaryOriginsRequest) (*pb.UpdateReverseProxyPrimaryOriginsResponse, error) {
 | 
			
		||||
func (this *ReverseProxyService) UpdateReverseProxyPrimaryOrigins(ctx context.Context, req *pb.UpdateReverseProxyPrimaryOriginsRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -102,11 +102,11 @@ func (this *ReverseProxyService) UpdateReverseProxyPrimaryOrigins(ctx context.Co
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateReverseProxyPrimaryOriginsResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改备用源站信息
 | 
			
		||||
func (this *ReverseProxyService) UpdateReverseProxyBackupOrigins(ctx context.Context, req *pb.UpdateReverseProxyBackupOriginsRequest) (*pb.UpdateReverseProxyBackupOriginsResponse, error) {
 | 
			
		||||
func (this *ReverseProxyService) UpdateReverseProxyBackupOrigins(ctx context.Context, req *pb.UpdateReverseProxyBackupOriginsRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -118,11 +118,11 @@ func (this *ReverseProxyService) UpdateReverseProxyBackupOrigins(ctx context.Con
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateReverseProxyBackupOriginsResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改是否启用
 | 
			
		||||
func (this *ReverseProxyService) UpdateReverseProxyIsOn(ctx context.Context, req *pb.UpdateReverseProxyIsOnRequest) (*pb.UpdateReverseProxyIsOnResponse, error) {
 | 
			
		||||
func (this *ReverseProxyService) UpdateReverseProxyIsOn(ctx context.Context, req *pb.UpdateReverseProxyIsOnRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -134,5 +134,5 @@ func (this *ReverseProxyService) UpdateReverseProxyIsOn(ctx context.Context, req
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateReverseProxyIsOnResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -33,7 +33,7 @@ func (this *ServerService) CreateServer(ctx context.Context, req *pb.CreateServe
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改服务
 | 
			
		||||
func (this *ServerService) UpdateServerBasic(ctx context.Context, req *pb.UpdateServerBasicRequest) (*pb.UpdateServerBasicResponse, error) {
 | 
			
		||||
func (this *ServerService) UpdateServerBasic(ctx context.Context, req *pb.UpdateServerBasicRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -71,11 +71,11 @@ func (this *ServerService) UpdateServerBasic(ctx context.Context, req *pb.Update
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateServerBasicResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改HTTP服务
 | 
			
		||||
func (this *ServerService) UpdateServerHTTP(ctx context.Context, req *pb.UpdateServerHTTPRequest) (*pb.UpdateServerHTTPResponse, error) {
 | 
			
		||||
func (this *ServerService) UpdateServerHTTP(ctx context.Context, req *pb.UpdateServerHTTPRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -106,11 +106,11 @@ func (this *ServerService) UpdateServerHTTP(ctx context.Context, req *pb.UpdateS
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateServerHTTPResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改HTTPS服务
 | 
			
		||||
func (this *ServerService) UpdateServerHTTPS(ctx context.Context, req *pb.UpdateServerHTTPSRequest) (*pb.UpdateServerHTTPSResponse, error) {
 | 
			
		||||
func (this *ServerService) UpdateServerHTTPS(ctx context.Context, req *pb.UpdateServerHTTPSRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -141,11 +141,11 @@ func (this *ServerService) UpdateServerHTTPS(ctx context.Context, req *pb.Update
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateServerHTTPSResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改TCP服务
 | 
			
		||||
func (this *ServerService) UpdateServerTCP(ctx context.Context, req *pb.UpdateServerTCPRequest) (*pb.UpdateServerTCPResponse, error) {
 | 
			
		||||
func (this *ServerService) UpdateServerTCP(ctx context.Context, req *pb.UpdateServerTCPRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -176,11 +176,11 @@ func (this *ServerService) UpdateServerTCP(ctx context.Context, req *pb.UpdateSe
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateServerTCPResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改TLS服务
 | 
			
		||||
func (this *ServerService) UpdateServerTLS(ctx context.Context, req *pb.UpdateServerTLSRequest) (*pb.UpdateServerTLSResponse, error) {
 | 
			
		||||
func (this *ServerService) UpdateServerTLS(ctx context.Context, req *pb.UpdateServerTLSRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -211,11 +211,11 @@ func (this *ServerService) UpdateServerTLS(ctx context.Context, req *pb.UpdateSe
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateServerTLSResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改Unix服务
 | 
			
		||||
func (this *ServerService) UpdateServerUnix(ctx context.Context, req *pb.UpdateServerUnixRequest) (*pb.UpdateServerUnixResponse, error) {
 | 
			
		||||
func (this *ServerService) UpdateServerUnix(ctx context.Context, req *pb.UpdateServerUnixRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -246,11 +246,11 @@ func (this *ServerService) UpdateServerUnix(ctx context.Context, req *pb.UpdateS
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateServerUnixResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改UDP服务
 | 
			
		||||
func (this *ServerService) UpdateServerUDP(ctx context.Context, req *pb.UpdateServerUDPRequest) (*pb.UpdateServerUDPResponse, error) {
 | 
			
		||||
func (this *ServerService) UpdateServerUDP(ctx context.Context, req *pb.UpdateServerUDPRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -281,11 +281,11 @@ func (this *ServerService) UpdateServerUDP(ctx context.Context, req *pb.UpdateSe
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateServerUDPResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改Web服务
 | 
			
		||||
func (this *ServerService) UpdateServerWeb(ctx context.Context, req *pb.UpdateServerWebRequest) (*pb.UpdateServerWebResponse, error) {
 | 
			
		||||
func (this *ServerService) UpdateServerWeb(ctx context.Context, req *pb.UpdateServerWebRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -316,11 +316,11 @@ func (this *ServerService) UpdateServerWeb(ctx context.Context, req *pb.UpdateSe
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateServerWebResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改反向代理服务
 | 
			
		||||
func (this *ServerService) UpdateServerReverseProxy(ctx context.Context, req *pb.UpdateServerReverseProxyRequest) (*pb.UpdateServerReverseProxyResponse, error) {
 | 
			
		||||
func (this *ServerService) UpdateServerReverseProxy(ctx context.Context, req *pb.UpdateServerReverseProxyRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -351,11 +351,11 @@ func (this *ServerService) UpdateServerReverseProxy(ctx context.Context, req *pb
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateServerReverseProxyResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改域名服务
 | 
			
		||||
func (this *ServerService) UpdateServerNames(ctx context.Context, req *pb.UpdateServerNamesRequest) (*pb.UpdateServerNamesResponse, error) {
 | 
			
		||||
func (this *ServerService) UpdateServerNames(ctx context.Context, req *pb.UpdateServerNamesRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@@ -386,7 +386,7 @@ func (this *ServerService) UpdateServerNames(ctx context.Context, req *pb.Update
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateServerNamesResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 计算服务数量
 | 
			
		||||
 
 | 
			
		||||
@@ -71,7 +71,7 @@ func (this *HTTPGzipService) FindEnabledHTTPGzipConfig(ctx context.Context, req
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 修改Gzip配置
 | 
			
		||||
func (this *HTTPGzipService) UpdateHTTPGzip(ctx context.Context, req *pb.UpdateHTTPGzipRequest) (*pb.UpdateHTTPGzipResponse, error) {
 | 
			
		||||
func (this *HTTPGzipService) UpdateHTTPGzip(ctx context.Context, req *pb.UpdateHTTPGzipRequest) (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -105,5 +105,5 @@ func (this *HTTPGzipService) UpdateHTTPGzip(ctx context.Context, req *pb.UpdateH
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.UpdateHTTPGzipResponse{}, nil
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/db/models"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/encrypt"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/utils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/iwind/TeaGo/lists"
 | 
			
		||||
	"github.com/iwind/TeaGo/maps"
 | 
			
		||||
	"google.golang.org/grpc/metadata"
 | 
			
		||||
@@ -116,3 +117,8 @@ func ValidateRequest(ctx context.Context, userTypes ...UserType) (userType UserT
 | 
			
		||||
		return t, m.GetInt64("userId"), nil
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 返回Update信息
 | 
			
		||||
func RPCUpdateSuccess() (*pb.RPCUpdateSuccess, error) {
 | 
			
		||||
	return &pb.RPCUpdateSuccess{}, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user