|
@@ -13,7 +13,6 @@ import (
|
|
|
"github.com/go-nunu/nunu-layout-advanced/internal/service/api/flexCdn"
|
|
|
"github.com/mozillazg/go-pinyin"
|
|
|
"github.com/spf13/viper"
|
|
|
- "go.uber.org/zap"
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
"gorm.io/gorm"
|
|
|
"strconv"
|
|
@@ -274,57 +273,19 @@ func (s *globalLimitService) AddGlobalLimit(ctx context.Context, req v1.GlobalLi
|
|
|
}
|
|
|
|
|
|
|
|
|
- outputTimeStr, err := s.ConversionTime(ctx, require.ExpiredAt)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
// 获取套餐ID
|
|
|
- maxProtection := strings.TrimSuffix(require.ConfigMaxProtection, "G")
|
|
|
- if maxProtection == "" {
|
|
|
- return fmt.Errorf("无效的配置 ConfigMaxProtection: '%s',数字部分为空", require.ConfigMaxProtection)
|
|
|
- }
|
|
|
- maxProtectionInt, err := strconv.Atoi(maxProtection)
|
|
|
- if err != nil {
|
|
|
- return fmt.Errorf("无效的配置 ConfigMaxProtection: '%s',无法转换为数字", require.ConfigMaxProtection)
|
|
|
- }
|
|
|
- var planId int64
|
|
|
- maxProtectionNum := 1
|
|
|
- if maxProtectionInt >= 2000 {
|
|
|
- maxProtectionNum = maxProtectionInt / 1000
|
|
|
- }
|
|
|
- NodeAreaName := fmt.Sprintf("%s-%dT",require.NodeArea, maxProtectionNum)
|
|
|
- planId, err = s.globalLimitRepository.GetNodeArea(ctx, NodeAreaName)
|
|
|
- if err != nil {
|
|
|
- if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
- planId = 0
|
|
|
- }else {
|
|
|
- return err
|
|
|
- }
|
|
|
- }
|
|
|
- if planId == 0 {
|
|
|
- // 安全冗余套餐
|
|
|
- planId = 6
|
|
|
- s.Logger.Warn("获取套餐Id失败", zap.String("节点区域", NodeAreaName), zap.String("防御阈值", require.ConfigMaxProtection),zap.Int64("套餐Id", int64(req.Uid)),zap.Int64("魔方套餐Id", int64(req.HostId)))
|
|
|
- }
|
|
|
+ //maxProtection := strings.TrimSuffix(require.ConfigMaxProtection, "G")
|
|
|
+ //if maxProtection == "" {
|
|
|
+ // return fmt.Errorf("无效的配置 ConfigMaxProtection: '%s',数字部分为空", require.ConfigMaxProtection)
|
|
|
+ //}
|
|
|
+ //maxProtectionInt, err := strconv.Atoi(maxProtection)
|
|
|
+ //if err != nil {
|
|
|
+ // return fmt.Errorf("无效的配置 ConfigMaxProtection: '%s',无法转换为数字", require.ConfigMaxProtection)
|
|
|
+ //}
|
|
|
|
|
|
|
|
|
- ruleId, err := s.cdnService.BindPlan(ctx, v1.Plan{
|
|
|
- UserId: userId,
|
|
|
- PlanId: planId,
|
|
|
- DayTo: outputTimeStr,
|
|
|
- Name: require.GlobalLimitName,
|
|
|
- IsFree: true,
|
|
|
- Period: "monthly",
|
|
|
- CountPeriod: 1,
|
|
|
- PeriodDayTo: outputTimeStr,
|
|
|
- })
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- if ruleId == 0 {
|
|
|
- return fmt.Errorf("分配套餐失败")
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
@@ -345,7 +306,6 @@ func (s *globalLimitService) AddGlobalLimit(ctx context.Context, req v1.GlobalLi
|
|
|
HostId: req.HostId,
|
|
|
Uid: req.Uid,
|
|
|
Name: require.GlobalLimitName,
|
|
|
- RuleId: int(ruleId),
|
|
|
GroupId: int(groupId),
|
|
|
CdnUid: int(userId),
|
|
|
Comment: req.Comment,
|
|
@@ -365,7 +325,6 @@ func (s *globalLimitService) AddGlobalLimit(ctx context.Context, req v1.GlobalLi
|
|
|
HostId: req.HostId,
|
|
|
Uid: req.Uid,
|
|
|
Name: require.GlobalLimitName,
|
|
|
- RuleId: int(ruleId),
|
|
|
GroupId: int(groupId),
|
|
|
CdnUid: int(userId),
|
|
|
Comment: req.Comment,
|
|
@@ -384,10 +343,7 @@ func (s *globalLimitService) EditGlobalLimit(ctx context.Context, req v1.GlobalL
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- data, err := s.globalLimitRepository.GetGlobalLimitByHostId(ctx, int64(req.HostId))
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
// 如果不存在实例,创建
|
|
|
gatewayIp, err := s.gatewayIpRep.GetGatewayipByHostIdAll(ctx, int64(req.HostId))
|
|
@@ -403,21 +359,6 @@ func (s *globalLimitService) EditGlobalLimit(ctx context.Context, req v1.GlobalL
|
|
|
|
|
|
|
|
|
|
|
|
- outputTimeStr, err := s.ConversionTime(ctx, require.ExpiredAt)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- err = s.cdnService.RenewPlan(ctx, v1.RenewalPlan{
|
|
|
- UserPlanId: int64(data.RuleId),
|
|
|
- DayTo: outputTimeStr,
|
|
|
- Period: "monthly",
|
|
|
- CountPeriod: 1,
|
|
|
- IsFree: true,
|
|
|
- PeriodDayTo: outputTimeStr,
|
|
|
- })
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
|
|
|
expiredAt, err := s.ConversionTimeUnix(ctx, require.ExpiredAt)
|
|
|
if err != nil {
|
|
@@ -509,14 +450,7 @@ func (s *globalLimitService) DeleteGlobalLimit(ctx context.Context, req v1.Globa
|
|
|
return nil
|
|
|
})
|
|
|
|
|
|
- // 删除套餐
|
|
|
- g.Go(func() error {
|
|
|
- e := s.cdnService.DelUserPlan(gCtx, int64(oldData.RuleId))
|
|
|
- if e != nil {
|
|
|
- return fmt.Errorf("删除套餐失败: %w", e)
|
|
|
- }
|
|
|
- return nil
|
|
|
- })
|
|
|
+
|
|
|
// 删除网站分组
|
|
|
g.Go(func() error {
|
|
|
e := s.cdnService.DelServerGroup(gCtx, int64(oldData.GroupId))
|