mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 16:00:24 +08:00 
			
		
		
		
	自定义页面支持用户操作
This commit is contained in:
		@@ -77,8 +77,9 @@ func (this *HTTPPageDAO) FindEnabledHTTPPage(tx *dbs.Tx, id int64) (*HTTPPage, e
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// CreatePage 创建Page
 | 
					// CreatePage 创建Page
 | 
				
			||||||
func (this *HTTPPageDAO) CreatePage(tx *dbs.Tx, 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 shared.BodyType, url string, body string, newStatus int) (pageId int64, err error) {
 | 
				
			||||||
	op := NewHTTPPageOperator()
 | 
						op := NewHTTPPageOperator()
 | 
				
			||||||
 | 
						op.UserId = userId
 | 
				
			||||||
	op.IsOn = true
 | 
						op.IsOn = true
 | 
				
			||||||
	op.State = HTTPPageStateEnabled
 | 
						op.State = HTTPPageStateEnabled
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -182,6 +183,26 @@ func (this *HTTPPageDAO) ComposePageConfig(tx *dbs.Tx, pageId int64, cacheMap *u
 | 
				
			|||||||
	return config, nil
 | 
						return config, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// CheckUserPage 检查用户页面
 | 
				
			||||||
 | 
					func (this *HTTPPageDAO) CheckUserPage(tx *dbs.Tx, userId int64, pageId int64) error {
 | 
				
			||||||
 | 
						if userId <= 0 || pageId <= 0 {
 | 
				
			||||||
 | 
							return ErrNotFound
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						b, err := this.Query(tx).
 | 
				
			||||||
 | 
							Pk(pageId).
 | 
				
			||||||
 | 
							Attr("userId", userId).
 | 
				
			||||||
 | 
							State(HTTPPageStateEnabled).
 | 
				
			||||||
 | 
							Exist()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !b {
 | 
				
			||||||
 | 
							return ErrNotFound
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NotifyUpdate 通知更新
 | 
					// NotifyUpdate 通知更新
 | 
				
			||||||
func (this *HTTPPageDAO) NotifyUpdate(tx *dbs.Tx, pageId int64) error {
 | 
					func (this *HTTPPageDAO) NotifyUpdate(tx *dbs.Tx, pageId int64) error {
 | 
				
			||||||
	webId, err := SharedHTTPWebDAO.FindEnabledWebIdWithPageId(tx, pageId)
 | 
						webId, err := SharedHTTPWebDAO.FindEnabledWebIdWithPageId(tx, pageId)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -622,5 +622,9 @@ func (this *APINode) unaryInterceptor(ctx context.Context, req interface{}, info
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return handler(ctx, req)
 | 
						result, err := handler(ctx, req)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							err = errors.New("'" + info.FullMethod + "()' says: " + err.Error())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return result, err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,32 +15,38 @@ type HTTPPageService struct {
 | 
				
			|||||||
// CreateHTTPPage 创建Page
 | 
					// CreateHTTPPage 创建Page
 | 
				
			||||||
func (this *HTTPPageService) CreateHTTPPage(ctx context.Context, req *pb.CreateHTTPPageRequest) (*pb.CreateHTTPPageResponse, error) {
 | 
					func (this *HTTPPageService) CreateHTTPPage(ctx context.Context, req *pb.CreateHTTPPageRequest) (*pb.CreateHTTPPageResponse, error) {
 | 
				
			||||||
	// 校验请求
 | 
						// 校验请求
 | 
				
			||||||
	_, err := this.ValidateAdmin(ctx, 0)
 | 
						_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tx := this.NullTx()
 | 
						var tx = this.NullTx()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pageId, err := models.SharedHTTPPageDAO.CreatePage(tx, req.StatusList, req.BodyType, req.Url, req.Body, types.Int(req.NewStatus))
 | 
						pageId, err := models.SharedHTTPPageDAO.CreatePage(tx, userId, req.StatusList, req.BodyType, req.Url, req.Body, types.Int(req.NewStatus))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return &pb.CreateHTTPPageResponse{PageId: pageId}, nil
 | 
						return &pb.CreateHTTPPageResponse{HttpPageId: pageId}, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UpdateHTTPPage 修改Page
 | 
					// UpdateHTTPPage 修改Page
 | 
				
			||||||
func (this *HTTPPageService) UpdateHTTPPage(ctx context.Context, req *pb.UpdateHTTPPageRequest) (*pb.RPCSuccess, error) {
 | 
					func (this *HTTPPageService) UpdateHTTPPage(ctx context.Context, req *pb.UpdateHTTPPageRequest) (*pb.RPCSuccess, error) {
 | 
				
			||||||
	// 校验请求
 | 
						// 校验请求
 | 
				
			||||||
	_, err := this.ValidateAdmin(ctx, 0)
 | 
						_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tx := this.NullTx()
 | 
						var tx = this.NullTx()
 | 
				
			||||||
 | 
						if userId > 0 {
 | 
				
			||||||
 | 
							err = models.SharedHTTPPageDAO.CheckUserPage(tx, userId, req.HttpPageId)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = models.SharedHTTPPageDAO.UpdatePage(tx, req.PageId, req.StatusList, req.BodyType, req.Url, req.Body, types.Int(req.NewStatus))
 | 
						err = models.SharedHTTPPageDAO.UpdatePage(tx, req.HttpPageId, req.StatusList, req.BodyType, req.Url, req.Body, types.Int(req.NewStatus))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -51,14 +57,20 @@ func (this *HTTPPageService) UpdateHTTPPage(ctx context.Context, req *pb.UpdateH
 | 
				
			|||||||
// FindEnabledHTTPPageConfig 查找单个Page配置
 | 
					// FindEnabledHTTPPageConfig 查找单个Page配置
 | 
				
			||||||
func (this *HTTPPageService) FindEnabledHTTPPageConfig(ctx context.Context, req *pb.FindEnabledHTTPPageConfigRequest) (*pb.FindEnabledHTTPPageConfigResponse, error) {
 | 
					func (this *HTTPPageService) FindEnabledHTTPPageConfig(ctx context.Context, req *pb.FindEnabledHTTPPageConfigRequest) (*pb.FindEnabledHTTPPageConfigResponse, error) {
 | 
				
			||||||
	// 校验请求
 | 
						// 校验请求
 | 
				
			||||||
	_, err := this.ValidateAdmin(ctx, 0)
 | 
						_, userId, err := this.ValidateAdminAndUser(ctx, 0, 0)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tx := this.NullTx()
 | 
						var tx = this.NullTx()
 | 
				
			||||||
 | 
						if userId > 0 {
 | 
				
			||||||
 | 
							err = models.SharedHTTPPageDAO.CheckUserPage(tx, userId, req.HttpPageId)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, err
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	config, err := models.SharedHTTPPageDAO.ComposePageConfig(tx, req.PageId, nil)
 | 
						config, err := models.SharedHTTPPageDAO.ComposePageConfig(tx, req.HttpPageId, nil)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user