Bladeren bron

feat(api): include consumed traffic in the client-get response (#4973)

GET /panel/api/clients/get/:email returned the quota (totalGB) but not
the bytes the client has actually used, forcing API consumers to scrape
it elsewhere. Add a sibling "usedTraffic" field (up+down, including the
cross-node global overlay) next to "client" and "inboundIds".
MHSanaei 3 dagen geleden
bovenliggende
commit
d1a13844b2
1 gewijzigde bestanden met toevoegingen van 8 en 1 verwijderingen
  1. 8 1
      internal/web/controller/client.go

+ 8 - 1
internal/web/controller/client.go

@@ -118,7 +118,14 @@ func (a *ClientController) get(c *gin.Context) {
 		return
 	}
 	rec.Flow = flow
-	jsonObj(c, gin.H{"client": rec, "inboundIds": inboundIds}, nil)
+	// Consumed bytes (up+down, including cross-node global overlay) so API
+	// consumers can pair usage with the client's totalGB quota (#4973).
+	// Best-effort: a traffic lookup failure must not break the client fetch.
+	var usedTraffic int64
+	if t, tErr := a.inboundService.GetClientTrafficByEmail(email); tErr == nil && t != nil {
+		usedTraffic = t.Up + t.Down
+	}
+	jsonObj(c, gin.H{"client": rec, "inboundIds": inboundIds, "usedTraffic": usedTraffic}, nil)
 }
 
 func (a *ClientController) create(c *gin.Context) {