Skip to content

Commit

Permalink
Fix:修复获取用户列表和在线设备列表时未正常重置资源的BUG
Browse files Browse the repository at this point in the history
  • Loading branch information
wyx2685 committed Sep 11, 2024
1 parent 6936a76 commit f7d5d89
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
39 changes: 20 additions & 19 deletions api/panel/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ func (c *Client) GetUserList() ([]UserInfo, error) {
SetHeader("If-None-Match", c.userEtag).
ForceContentType("application/json").
Get(path)
if err = c.checkResponse(r, path, err); err != nil {
return nil, err
}
if r != nil {
defer r.RawResponse.Body.Close()
} else {
return nil, fmt.Errorf("received nil response")
if r == nil || r.RawResponse == nil {
return nil, fmt.Errorf("received nil response or raw response")
}
defer r.RawResponse.Body.Close()

if r.StatusCode() == 304 {
return nil, nil
} else {
if err := json.Unmarshal(r.Body(), c.UserList); err != nil {
return nil, fmt.Errorf("unmarshal user list error: %w", err)
}
c.userEtag = r.Header().Get("ETag")
}
return c.UserList.Users, nil

if err = c.checkResponse(r, path, err); err != nil {
return nil, err
}
userlist := &UserListBody{}
if err := json.Unmarshal(r.Body(), userlist); err != nil {
return nil, fmt.Errorf("unmarshal user list error: %w", err)
}
c.userEtag = r.Header().Get("ETag")
return userlist.Users, nil
}

// GetUserAlive will fetch the alive_ip count for users
Expand All @@ -60,14 +60,15 @@ func (c *Client) GetUserAlive() (map[int]int, error) {
r, err := c.client.R().
ForceContentType("application/json").
Get(path)
if err != nil || r.StatusCode() >= 399 {
return make(map[int]int), nil
if r == nil || r.RawResponse == nil {
return nil, fmt.Errorf("received nil response or raw response")
}
defer r.RawResponse.Body.Close()

if r != nil {
defer r.RawResponse.Body.Close()
} else {
return nil, fmt.Errorf("received nil response")
c.AliveMap = &AliveMap{}
if err != nil || r.StatusCode() >= 399 {
c.AliveMap.Alive = make(map[int]int)
return c.AliveMap.Alive, nil
}

if err := json.Unmarshal(r.Body(), c.AliveMap); err != nil {
Expand Down
5 changes: 0 additions & 5 deletions core/xray/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,6 @@ func buildV2ray(config *conf.Options, nodeInfo *panel.NodeInfo, inbound *coreCon
if err != nil {
return fmt.Errorf("unmarshal grpc settings error: %s", err)
}
case "quic":
err := json.Unmarshal(v.NetworkSettings, &inbound.StreamSetting.QUICSettings)
if err != nil {
return fmt.Errorf("unmarshal grpc settings error: %s", err)
}
case "httpupgrade":
err := json.Unmarshal(v.NetworkSettings, &inbound.StreamSetting.HTTPUPGRADESettings)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions limiter/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ func DeleteLimiter(tag string) {
func (l *Limiter) UpdateUser(tag string, added []panel.UserInfo, deleted []panel.UserInfo) {
for i := range deleted {
l.UserLimitInfo.Delete(format.UserTag(tag, deleted[i].Uuid))
l.UserOnlineIP.Delete(format.UserTag(tag, deleted[i].Uuid))
delete(l.UUIDtoUID, deleted[i].Uuid)
delete(l.AliveList, deleted[i].Id)
}
for i := range added {
userLimit := &UserLimitInfo{
Expand Down

0 comments on commit f7d5d89

Please sign in to comment.