mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 07:50:25 +08:00 
			
		
		
		
	增加若干API
This commit is contained in:
		@@ -862,3 +862,29 @@ func (this *HTTPFirewallPolicyService) CheckHTTPFirewallPolicyIPStatus(ctx conte
 | 
			
		||||
		RegionProvince: nil,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FindServerIdWithHTTPFirewallPolicyId 获取防火墙对应的网站ID
 | 
			
		||||
func (this *HTTPFirewallPolicyService) FindServerIdWithHTTPFirewallPolicyId(ctx context.Context, req *pb.FindServerIdWithHTTPFirewallPolicyIdRequest) (*pb.FindServerIdWithHTTPFirewallPolicyIdResponse, error) {
 | 
			
		||||
	_, userId, err := this.ValidateAdminAndUser(ctx, true)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var tx = this.NullTx()
 | 
			
		||||
	serverId, err := models.SharedHTTPFirewallPolicyDAO.FindServerIdWithFirewallPolicyId(tx, req.HttpFirewallPolicyId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// check user
 | 
			
		||||
	if serverId > 0 && userId > 0 {
 | 
			
		||||
		err = models.SharedServerDAO.CheckUserServer(tx, userId, serverId)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.FindServerIdWithHTTPFirewallPolicyIdResponse{
 | 
			
		||||
		ServerId: serverId,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -782,3 +782,38 @@ func (this *IPItemService) UpdateIPItemsRead(ctx context.Context, req *pb.Update
 | 
			
		||||
	}
 | 
			
		||||
	return this.Success()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FindServerIdWithIPItemId 查找IP对应的名单所属网站ID
 | 
			
		||||
func (this *IPItemService) FindServerIdWithIPItemId(ctx context.Context, req *pb.FindServerIdWithIPItemIdRequest) (*pb.FindServerIdWithIPItemIdResponse, error) {
 | 
			
		||||
	_, userId, err := this.ValidateAdminAndUser(ctx, true)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var tx = this.NullTx()
 | 
			
		||||
	listId, err := models.SharedIPItemDAO.FindItemListId(tx, req.IpItemId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if listId > 0 {
 | 
			
		||||
		var serverId int64
 | 
			
		||||
		serverId, err = models.SharedIPListDAO.FindServerIdWithListId(tx, listId)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if serverId > 0 {
 | 
			
		||||
			// check user
 | 
			
		||||
			if userId > 0 {
 | 
			
		||||
				err = models.SharedServerDAO.CheckUserServer(tx, userId, serverId)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					return nil, err
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			return &pb.FindServerIdWithIPItemIdResponse{ServerId: serverId}, nil
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.FindServerIdWithIPItemIdResponse{ServerId: 0}, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -224,3 +224,29 @@ func (this *IPListService) FindEnabledIPListContainsIP(ctx context.Context, req
 | 
			
		||||
	}
 | 
			
		||||
	return &pb.FindEnabledIPListContainsIPResponse{IpLists: pbLists}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FindServerIdWithIPListId 查找IP名单对应的网站ID
 | 
			
		||||
func (this *IPListService) FindServerIdWithIPListId(ctx context.Context, req *pb.FindServerIdWithIPListIdRequest) (*pb.FindServerIdWithIPListIdResponse, error) {
 | 
			
		||||
	_, userId, err := this.ValidateAdminAndUser(ctx, true)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var tx = this.NullTx()
 | 
			
		||||
	serverId, err := models.SharedIPListDAO.FindServerIdWithListId(tx, req.IpListId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// check user
 | 
			
		||||
	if serverId > 0 && userId > 0 {
 | 
			
		||||
		err = models.SharedServerDAO.CheckUserServer(tx, userId, serverId)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.FindServerIdWithIPListIdResponse{
 | 
			
		||||
		ServerId: serverId,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2890,6 +2890,7 @@ func (this *ServerService) FindServerUserPlan(ctx context.Context, req *pb.FindS
 | 
			
		||||
			User:   nil,
 | 
			
		||||
			Plan: &pb.Plan{
 | 
			
		||||
				Id:                        int64(plan.Id),
 | 
			
		||||
				IsOn:                      plan.IsOn,
 | 
			
		||||
				Name:                      plan.Name,
 | 
			
		||||
				PriceType:                 plan.PriceType,
 | 
			
		||||
				TrafficPriceJSON:          plan.TrafficPrice,
 | 
			
		||||
@@ -2897,6 +2898,8 @@ func (this *ServerService) FindServerUserPlan(ctx context.Context, req *pb.FindS
 | 
			
		||||
				TotalServers:              types.Int32(plan.TotalServers),
 | 
			
		||||
				TotalServerNames:          types.Int32(plan.TotalServerNames),
 | 
			
		||||
				TotalServerNamesPerServer: types.Int32(plan.TotalServerNamesPerServer),
 | 
			
		||||
				HasFullFeatures:           plan.HasFullFeatures,
 | 
			
		||||
				FeaturesJSON:              plan.Features,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}, nil
 | 
			
		||||
 
 | 
			
		||||
@@ -618,31 +618,6 @@ func (this *UserService) UpdateAllUsersFeatures(ctx context.Context, req *pb.Upd
 | 
			
		||||
	return this.Success()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FindUserFeatures 获取用户所有的功能列表
 | 
			
		||||
func (this *UserService) FindUserFeatures(ctx context.Context, req *pb.FindUserFeaturesRequest) (*pb.FindUserFeaturesResponse, error) {
 | 
			
		||||
	_, userId, err := this.ValidateAdminAndUser(ctx, false)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	if userId > 0 {
 | 
			
		||||
		req.UserId = userId
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var tx = this.NullTx()
 | 
			
		||||
 | 
			
		||||
	features, err := models.SharedUserDAO.FindUserFeatures(tx, req.UserId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	result := []*pb.UserFeature{}
 | 
			
		||||
	for _, feature := range features {
 | 
			
		||||
		result = append(result, feature.ToPB())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.FindUserFeaturesResponse{Features: result}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FindAllUserFeatureDefinitions 获取所有的功能定义
 | 
			
		||||
func (this *UserService) FindAllUserFeatureDefinitions(ctx context.Context, req *pb.FindAllUserFeatureDefinitionsRequest) (*pb.FindAllUserFeatureDefinitionsResponse, error) {
 | 
			
		||||
	_, err := this.ValidateAdmin(ctx)
 | 
			
		||||
@@ -650,8 +625,8 @@ func (this *UserService) FindAllUserFeatureDefinitions(ctx context.Context, req
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	features := userconfigs.FindAllUserFeatures()
 | 
			
		||||
	result := []*pb.UserFeature{}
 | 
			
		||||
	var features = userconfigs.FindAllUserFeatures()
 | 
			
		||||
	var result = []*pb.UserFeature{}
 | 
			
		||||
	for _, feature := range features {
 | 
			
		||||
		result = append(result, feature.ToPB())
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -89,3 +89,28 @@ func (this *UserService) RegisterUser(ctx context.Context, req *pb.RegisterUserR
 | 
			
		||||
		RequireEmailVerification: requireEmailVerification,
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FindUserFeatures 获取用户所有的功能列表
 | 
			
		||||
func (this *UserService) FindUserFeatures(ctx context.Context, req *pb.FindUserFeaturesRequest) (*pb.FindUserFeaturesResponse, error) {
 | 
			
		||||
	_, userId, err := this.ValidateAdminAndUser(ctx, false)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	if userId > 0 {
 | 
			
		||||
		req.UserId = userId
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var tx = this.NullTx()
 | 
			
		||||
 | 
			
		||||
	features, err := models.SharedUserDAO.FindUserFeatures(tx, req.UserId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	result := []*pb.UserFeature{}
 | 
			
		||||
	for _, feature := range features {
 | 
			
		||||
		result = append(result, feature.ToPB())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.FindUserFeaturesResponse{Features: result}, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user