mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2026-03-20 00:05:39 +08:00
阶段性提交
This commit is contained in:
@@ -45,7 +45,9 @@ func (this *HTTPWebService) FindEnabledHTTPWeb(ctx context.Context, req *pb.Find
|
||||
|
||||
result := &pb.HTTPWeb{}
|
||||
result.Id = int64(web.Id)
|
||||
result.IsOn = web.IsOn == 1
|
||||
result.Root = web.Root
|
||||
result.GzipId = int64(web.GzipId)
|
||||
return &pb.FindEnabledHTTPWebResponse{Web: result}, nil
|
||||
}
|
||||
|
||||
@@ -64,3 +66,19 @@ func (this *HTTPWebService) UpdateHTTPWeb(ctx context.Context, req *pb.UpdateHTT
|
||||
|
||||
return &pb.UpdateHTTPWebResponse{}, nil
|
||||
}
|
||||
|
||||
// 修改Gzip配置
|
||||
func (this *HTTPWebService) UpdateHTTPWebGzip(ctx context.Context, req *pb.UpdateHTTPWebGzipRequest) (*pb.UpdateHTTPWebGzipResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.SharedHTTPWebDAO.UpdateWebGzip(req.WebId, req.GzipId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.UpdateHTTPWebGzipResponse{}, nil
|
||||
}
|
||||
|
||||
@@ -120,3 +120,19 @@ func (this *ReverseProxyService) UpdateReverseProxyBackupOrigins(ctx context.Con
|
||||
|
||||
return &pb.UpdateReverseProxyBackupOriginsResponse{}, nil
|
||||
}
|
||||
|
||||
// 修改是否启用
|
||||
func (this *ReverseProxyService) UpdateReverseProxyIsOn(ctx context.Context, req *pb.UpdateReverseProxyIsOnRequest) (*pb.UpdateReverseProxyIsOnResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.SharedReverseProxyDAO.UpdateReverseProxyIsOn(req.ReverseProxyId, req.IsOn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.UpdateReverseProxyIsOnResponse{}, nil
|
||||
}
|
||||
|
||||
@@ -426,6 +426,12 @@ func (this *ServerService) ListEnabledServers(ctx context.Context, req *pb.ListE
|
||||
Config: []byte(server.Config),
|
||||
Name: server.Name,
|
||||
Description: server.Description,
|
||||
HttpJSON: []byte(server.Http),
|
||||
HttpsJSON: []byte(server.Https),
|
||||
TcpJSON: []byte(server.Tcp),
|
||||
TlsJSON: []byte(server.Tls),
|
||||
UnixJSON: []byte(server.Unix),
|
||||
UdpJSON: []byte(server.Udp),
|
||||
IncludeNodes: []byte(server.IncludeNodes),
|
||||
ExcludeNodes: []byte(server.ExcludeNodes),
|
||||
CreatedAt: int64(server.CreatedAt),
|
||||
@@ -497,6 +503,7 @@ func (this *ServerService) FindEnabledServer(ctx context.Context, req *pb.FindEn
|
||||
Name: server.Name,
|
||||
Description: server.Description,
|
||||
Config: []byte(server.Config),
|
||||
ServerNamesJON: []byte(server.ServerNames),
|
||||
HttpJSON: []byte(server.Http),
|
||||
HttpsJSON: []byte(server.Https),
|
||||
TcpJSON: []byte(server.Tcp),
|
||||
@@ -532,7 +539,7 @@ func (this *ServerService) FindEnabledServerType(ctx context.Context, req *pb.Fi
|
||||
}
|
||||
|
||||
// 查找反向代理设置
|
||||
func (this *ServerService) FindServerReverseProxy(ctx context.Context, req *pb.FindServerReverseProxyRequest) (*pb.FindServerReverseProxyResponse, error) {
|
||||
func (this *ServerService) FindServerReverseProxyConfig(ctx context.Context, req *pb.FindServerReverseProxyConfigRequest) (*pb.FindServerReverseProxyConfigResponse, error) {
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -544,12 +551,27 @@ func (this *ServerService) FindServerReverseProxy(ctx context.Context, req *pb.F
|
||||
}
|
||||
|
||||
if reverseProxy == nil {
|
||||
return &pb.FindServerReverseProxyResponse{Config: nil}, nil
|
||||
return &pb.FindServerReverseProxyConfigResponse{Config: nil}, nil
|
||||
}
|
||||
|
||||
configData, err := json.Marshal(reverseProxy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.FindServerReverseProxyResponse{Config: configData}, nil
|
||||
return &pb.FindServerReverseProxyConfigResponse{Config: configData}, nil
|
||||
}
|
||||
|
||||
// 初始化Web设置
|
||||
func (this *ServerService) InitServerWeb(ctx context.Context, req *pb.InitServerWebRequest) (*pb.InitServerWebResponse, error) {
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
webId, err := models.SharedServerDAO.InitServerWeb(req.ServerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.InitServerWebResponse{WebId: webId}, nil
|
||||
}
|
||||
|
||||
109
internal/rpc/services/sevice_http_gzip.go
Normal file
109
internal/rpc/services/sevice_http_gzip.go
Normal file
@@ -0,0 +1,109 @@
|
||||
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/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
)
|
||||
|
||||
type HTTPGzipService struct {
|
||||
}
|
||||
|
||||
// 创建Gzip配置
|
||||
func (this *HTTPGzipService) CreateHTTPGzip(ctx context.Context, req *pb.CreateHTTPGzipRequest) (*pb.CreateHTTPGzipResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
minLengthJSON := []byte{}
|
||||
if req.MinLength != nil {
|
||||
minLengthJSON, err = (&shared.SizeCapacity{
|
||||
Count: req.MinLength.Count,
|
||||
Unit: req.MinLength.Unit,
|
||||
}).AsJSON()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
maxLengthJSON := []byte{}
|
||||
if req.MaxLength != nil {
|
||||
maxLengthJSON, err = (&shared.SizeCapacity{
|
||||
Count: req.MaxLength.Count,
|
||||
Unit: req.MaxLength.Unit,
|
||||
}).AsJSON()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
gzipId, err := models.SharedHTTPGzipDAO.CreateGzip(int(req.Level), minLengthJSON, maxLengthJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.CreateHTTPGzipResponse{GzipId: gzipId}, nil
|
||||
}
|
||||
|
||||
// 查找Gzip
|
||||
func (this *HTTPGzipService) FindEnabledHTTPGzipConfig(ctx context.Context, req *pb.FindEnabledGzipConfigRequest) (*pb.FindEnabledGzipConfigResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
config, err := models.SharedHTTPGzipDAO.ComposeGzipConfig(req.GzipId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
configData, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pb.FindEnabledGzipConfigResponse{Config: configData}, nil
|
||||
}
|
||||
|
||||
// 修改Gzip配置
|
||||
func (this *HTTPGzipService) UpdateHTTPGzip(ctx context.Context, req *pb.UpdateHTTPGzipRequest) (*pb.UpdateHTTPGzipResponse, error) {
|
||||
// 校验请求
|
||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
minLengthJSON := []byte{}
|
||||
if req.MinLength != nil {
|
||||
minLengthJSON, err = (&shared.SizeCapacity{
|
||||
Count: req.MinLength.Count,
|
||||
Unit: req.MinLength.Unit,
|
||||
}).AsJSON()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
maxLengthJSON := []byte{}
|
||||
if req.MaxLength != nil {
|
||||
maxLengthJSON, err = (&shared.SizeCapacity{
|
||||
Count: req.MaxLength.Count,
|
||||
Unit: req.MaxLength.Unit,
|
||||
}).AsJSON()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
err = models.SharedHTTPGzipDAO.UpdateGzip(req.GzipId, int(req.Level), minLengthJSON, maxLengthJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.UpdateHTTPGzipResponse{}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user