mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
feat: show online user id
Some checks are pending
CodeQL / Analyze (go) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
Contributors / contributors (push) Waiting to run
Sync / sync-to-jihulab (push) Waiting to run
Run Tests / tests (macos) (push) Waiting to run
Run Tests / tests (ubuntu) (push) Waiting to run
Run Tests / tests (windows) (push) Waiting to run
Some checks are pending
CodeQL / Analyze (go) (push) Waiting to run
CodeQL / Analyze (javascript) (push) Waiting to run
Contributors / contributors (push) Waiting to run
Sync / sync-to-jihulab (push) Waiting to run
Run Tests / tests (macos) (push) Waiting to run
Run Tests / tests (ubuntu) (push) Waiting to run
Run Tests / tests (windows) (push) Waiting to run
This commit is contained in:
parent
d50605d668
commit
5128bfff61
@ -33,7 +33,7 @@ func listBlockedAddress(c *gin.Context) (*model.Value[[]*model.WAF], error) {
|
||||
}
|
||||
|
||||
var waf []*model.WAF
|
||||
if err := singleton.DB.Limit(limit).Offset(offset).Find(&waf).Error; err != nil {
|
||||
if err := singleton.DB.Order("block_timestamp DESC").Limit(limit).Offset(offset).Find(&waf).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,14 @@ func serverStream(c *gin.Context) (any, error) {
|
||||
userIp = c.RemoteIP()
|
||||
}
|
||||
|
||||
u, isMember := c.Get(model.CtxKeyAuthorizedUser)
|
||||
var userId uint64
|
||||
if isMember {
|
||||
userId = u.(*model.User).ID
|
||||
}
|
||||
|
||||
singleton.AddOnlineUser(connId, &model.OnlineUser{
|
||||
UserID: userId,
|
||||
IP: userIp,
|
||||
ConnectedAt: time.Now(),
|
||||
Conn: conn,
|
||||
@ -128,7 +135,7 @@ func serverStream(c *gin.Context) (any, error) {
|
||||
|
||||
count := 0
|
||||
for {
|
||||
stat, err := getServerStat(c, count == 0)
|
||||
stat, err := getServerStat(count == 0, isMember)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@ -149,9 +156,7 @@ func serverStream(c *gin.Context) (any, error) {
|
||||
|
||||
var requestGroup singleflight.Group
|
||||
|
||||
func getServerStat(c *gin.Context, withPublicNote bool) ([]byte, error) {
|
||||
_, isMember := c.Get(model.CtxKeyAuthorizedUser)
|
||||
authorized := isMember // TODO || isViewPasswordVerfied
|
||||
func getServerStat(withPublicNote, authorized bool) ([]byte, error) {
|
||||
v, err, _ := requestGroup.Do(fmt.Sprintf("serverStats::%t", authorized), func() (interface{}, error) {
|
||||
singleton.SortedServerLock.RLock()
|
||||
defer singleton.SortedServerLock.RUnlock()
|
||||
|
@ -9,7 +9,7 @@
|
||||
name: "Official"
|
||||
repository: "https://github.com/hamster1963/nezha-dash-v1"
|
||||
author: "hamster1963"
|
||||
version: "v1.8.0"
|
||||
version: "v1.8.1"
|
||||
isofficial: true
|
||||
- path: "nazhua-dist"
|
||||
name: "Nazhua"
|
||||
|
Loading…
Reference in New Issue
Block a user