-
Notifications
You must be signed in to change notification settings - Fork 5
/
deleteCount.go
82 lines (68 loc) · 1.85 KB
/
deleteCount.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2023 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package iplists
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/types"
"strings"
)
type DeleteCountAction struct {
actionutils.ParentAction
}
func (this *DeleteCountAction) RunPost(params struct {
Ip string
Keyword string
GlobalOnly bool
Unread bool
EventLevel string
ListType string
Count int64
}) {
var count = params.Count
if count <= 0 || count >= 100_000 {
this.Fail("'count' 参数错误")
return
}
itemIdsResp, err := this.RPC().IPItemRPC().ListAllIPItemIds(this.AdminContext(), &pb.ListAllIPItemIdsRequest{
Keyword: params.Keyword,
GlobalOnly: params.GlobalOnly,
Unread: params.Unread,
EventLevel: params.EventLevel,
ListType: params.ListType,
Ip: params.Ip,
Offset: 0,
Size: count,
})
if err != nil {
this.ErrorPage(err)
return
}
var itemIds = itemIdsResp.IpItemIds
if len(itemIds) == 0 {
this.Success()
}
// 记录日志
defer func() {
var itemIdStrings = []string{}
for _, itemId := range itemIds {
itemIdStrings = append(itemIdStrings, types.String(itemId))
}
var itemIdsDescription = ""
if len(itemIdStrings) > 10 {
itemIdsDescription = strings.Join(itemIdStrings[:10], ", ") + " ..."
} else {
itemIdsDescription = strings.Join(itemIdStrings, ", ")
}
this.CreateLogInfo(codes.IPList_LogDeleteIPBatch, itemIdsDescription)
}()
_, err = this.RPC().IPItemRPC().DeleteIPItems(this.AdminContext(), &pb.DeleteIPItemsRequest{IpItemIds: itemIds})
if err != nil {
this.ErrorPage(err)
return
}
// 通知左侧菜单Badge更新
helpers.NotifyIPItemsCountChanges()
this.Success()
}