mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	自定义页面增加“跳转URL”功能
This commit is contained in:
		@@ -7,7 +7,7 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/db/models"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/utils/regexputils"
 | 
			
		||||
	"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"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -30,7 +30,7 @@ func (this *HTTPPageService) CreateHTTPPage(ctx context.Context, req *pb.CreateH
 | 
			
		||||
	const maxBodyLength = 32 * 1024
 | 
			
		||||
 | 
			
		||||
	switch req.BodyType {
 | 
			
		||||
	case shared.BodyTypeURL:
 | 
			
		||||
	case serverconfigs.HTTPPageBodyTypeURL:
 | 
			
		||||
		if len(req.Url) > maxURLLength {
 | 
			
		||||
			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
 | 
			
		||||
			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 {
 | 
			
		||||
			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
 | 
			
		||||
 | 
			
		||||
	switch req.BodyType {
 | 
			
		||||
	case shared.BodyTypeURL:
 | 
			
		||||
	case serverconfigs.HTTPPageBodyTypeURL:
 | 
			
		||||
		if len(req.Url) > maxURLLength {
 | 
			
		||||
			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
 | 
			
		||||
			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 {
 | 
			
		||||
			return nil, errors.New("'body' too long")
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,6 @@ import (
 | 
			
		||||
	"github.com/TeaOSLab/EdgeAPI/internal/utils/regexputils"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
 | 
			
		||||
	"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
 | 
			
		||||
	"github.com/iwind/TeaGo/dbs"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -365,7 +364,7 @@ func (this *HTTPWebService) UpdateHTTPWebShutdown(ctx context.Context, req *pb.U
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		switch shutdownConfig.BodyType {
 | 
			
		||||
		case shared.BodyTypeURL:
 | 
			
		||||
		case serverconfigs.HTTPPageBodyTypeURL:
 | 
			
		||||
			if len(shutdownConfig.URL) > maxURLLength {
 | 
			
		||||
				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
 | 
			
		||||
				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 {
 | 
			
		||||
				return nil, errors.New("'body' too long")
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user