fix report bug

This commit is contained in:
Yuzuki999 2022-12-23 01:52:44 +08:00
parent a3717c1e63
commit b07c9f0b6b
3 changed files with 24 additions and 11 deletions

View File

@ -4,7 +4,6 @@ import (
"github.com/goccy/go-json"
"regexp"
"strconv"
"strings"
)
type NodeInfo struct {
@ -62,12 +61,10 @@ func (c *Client) GetNodeInfo() (nodeInfo *NodeInfo, err error) {
nodeInfo.NodeType = c.NodeType
for i := range nodeInfo.Routes { // parse rules from routes
if nodeInfo.Routes[i].Action == "block" {
for _, v := range strings.Split(nodeInfo.Routes[i].Match, ",") {
nodeInfo.Rules = append(nodeInfo.Rules, DestinationRule{
ID: nodeInfo.Routes[i].Id,
Pattern: regexp.MustCompile(v),
})
}
nodeInfo.Rules = append(nodeInfo.Rules, DestinationRule{
ID: nodeInfo.Routes[i].Id,
Pattern: regexp.MustCompile(nodeInfo.Routes[i].Match),
})
}
}
nodeInfo.Routes = nil

View File

@ -6,7 +6,9 @@ import (
"testing"
)
func TestClient_GetNodeInfo(t *testing.T) {
var client Panel
func init() {
c, err := New(&conf.ApiConfig{
APIHost: "http://127.0.0.1",
Key: "token",
@ -14,7 +16,21 @@ func TestClient_GetNodeInfo(t *testing.T) {
NodeID: 1,
})
if err != nil {
log.Print(err)
log.Panic(err)
}
log.Println(c.GetNodeInfo())
client = c
}
func TestClient_GetNodeInfo(t *testing.T) {
log.Println(client.GetNodeInfo())
}
func TestClient_ReportUserTraffic(t *testing.T) {
log.Println(client.ReportUserTraffic([]UserTraffic{
{
UID: 10372,
Upload: 1000,
Download: 1000,
},
}))
}

View File

@ -62,7 +62,7 @@ func (c *Client) ReportUserTraffic(userTraffic []UserTraffic) error {
}
const path = "/api/v1/server/UniProxy/push"
res, err := c.client.R().
SetBody(userTraffic).
SetBody(data).
ForceContentType("application/json").
Post(path)
err = c.checkResponse(res, path, err)