Fix:修复获取用户列表和在线设备列表时未正常重置资源的BUG

This commit is contained in:
wyx2685 2024-09-12 00:10:31 +09:00
parent 6936a76724
commit f7d5d891c3
No known key found for this signature in database
GPG Key ID: 8827A30FF1DB1379
3 changed files with 22 additions and 24 deletions

View File

@ -34,24 +34,24 @@ func (c *Client) GetUserList() ([]UserInfo, error) {
SetHeader("If-None-Match", c.userEtag). SetHeader("If-None-Match", c.userEtag).
ForceContentType("application/json"). ForceContentType("application/json").
Get(path) Get(path)
if err = c.checkResponse(r, path, err); err != nil { if r == nil || r.RawResponse == nil {
return nil, err return nil, fmt.Errorf("received nil response or raw response")
}
if r != nil {
defer r.RawResponse.Body.Close()
} else {
return nil, fmt.Errorf("received nil response")
} }
defer r.RawResponse.Body.Close()
if r.StatusCode() == 304 { if r.StatusCode() == 304 {
return nil, nil 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 // GetUserAlive will fetch the alive_ip count for users
@ -60,14 +60,15 @@ func (c *Client) GetUserAlive() (map[int]int, error) {
r, err := c.client.R(). r, err := c.client.R().
ForceContentType("application/json"). ForceContentType("application/json").
Get(path) Get(path)
if err != nil || r.StatusCode() >= 399 { if r == nil || r.RawResponse == nil {
return make(map[int]int), nil return nil, fmt.Errorf("received nil response or raw response")
} }
defer r.RawResponse.Body.Close()
if r != nil { c.AliveMap = &AliveMap{}
defer r.RawResponse.Body.Close() if err != nil || r.StatusCode() >= 399 {
} else { c.AliveMap.Alive = make(map[int]int)
return nil, fmt.Errorf("received nil response") return c.AliveMap.Alive, nil
} }
if err := json.Unmarshal(r.Body(), c.AliveMap); err != nil { if err := json.Unmarshal(r.Body(), c.AliveMap); err != nil {

View File

@ -213,11 +213,6 @@ func buildV2ray(config *conf.Options, nodeInfo *panel.NodeInfo, inbound *coreCon
if err != nil { if err != nil {
return fmt.Errorf("unmarshal grpc settings error: %s", err) 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": case "httpupgrade":
err := json.Unmarshal(v.NetworkSettings, &inbound.StreamSetting.HTTPUPGRADESettings) err := json.Unmarshal(v.NetworkSettings, &inbound.StreamSetting.HTTPUPGRADESettings)
if err != nil { if err != nil {

View File

@ -104,7 +104,9 @@ func DeleteLimiter(tag string) {
func (l *Limiter) UpdateUser(tag string, added []panel.UserInfo, deleted []panel.UserInfo) { func (l *Limiter) UpdateUser(tag string, added []panel.UserInfo, deleted []panel.UserInfo) {
for i := range deleted { for i := range deleted {
l.UserLimitInfo.Delete(format.UserTag(tag, deleted[i].Uuid)) 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.UUIDtoUID, deleted[i].Uuid)
delete(l.AliveList, deleted[i].Id)
} }
for i := range added { for i := range added {
userLimit := &UserLimitInfo{ userLimit := &UserLimitInfo{