From e4deba15ddbd1bf7bbccdb1d2a5be8c8d58d2839 Mon Sep 17 00:00:00 2001 From: thh1451 Date: Sat, 27 Jul 2024 11:28:21 +0200 Subject: [PATCH] optimization and reduce the size of the data passed by api --- api/v2raysocks/model.go | 4 ++++ api/v2raysocks/v2raysocks.go | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/api/v2raysocks/model.go b/api/v2raysocks/model.go index c46ef990..9dd9f01c 100644 --- a/api/v2raysocks/model.go +++ b/api/v2raysocks/model.go @@ -19,6 +19,10 @@ type NodeOnline struct { IP string `json:"ip"` } +type IllegalItem struct { + UID int `json:"user_id"` +} + type REALITYConfig struct { Dest string `json:"dest,omitempty"` ProxyProtocolVer uint64 `json:"proxy_protocol_ver,omitempty"` diff --git a/api/v2raysocks/v2raysocks.go b/api/v2raysocks/v2raysocks.go index cd621ed2..dc7206e7 100644 --- a/api/v2raysocks/v2raysocks.go +++ b/api/v2raysocks/v2raysocks.go @@ -364,6 +364,26 @@ func (c *APIClient) ReportNodeOnlineUsers(onlineUserList *[]api.OnlineUser) erro // ReportIllegal implements the API interface func (c *APIClient) ReportIllegal(detectResultList *[]api.DetectResult) error { + data := make([]IllegalItem, len(*detectResultList)) + for i, r := range *detectResultList { + data[i] = IllegalItem{ + UID: r.UID, + } + } + + res, err := c.client.R(). + SetQueryParam("node_id", strconv.Itoa(c.NodeID)). + SetQueryParams(map[string]string{ + "act": "illegal", + "node_type": strings.ToLower(c.NodeType), + }). + SetBody(data). + ForceContentType("application/json"). + Post(c.APIHost) + _, err = c.parseResponse(res, "", err) + if err != nil { + return err + } return nil }