mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-08-23 11:26:52 +00:00
Endpoint for updating client traffic by email (#3259)
* Update api.go * Update inbound.go * Update inbound.go
This commit is contained in:
parent
fa45bf87de
commit
b1ab156e42
3 changed files with 41 additions and 0 deletions
|
@ -47,6 +47,7 @@ func (a *APIController) initRouter(g *gin.RouterGroup) {
|
||||||
{"POST", "/resetAllClientTraffics/:id", a.inboundController.resetAllClientTraffics},
|
{"POST", "/resetAllClientTraffics/:id", a.inboundController.resetAllClientTraffics},
|
||||||
{"POST", "/delDepletedClients/:id", a.inboundController.delDepletedClients},
|
{"POST", "/delDepletedClients/:id", a.inboundController.delDepletedClients},
|
||||||
{"POST", "/onlines", a.inboundController.onlines},
|
{"POST", "/onlines", a.inboundController.onlines},
|
||||||
|
{"POST", "/updateClientTraffic/:email", a.inboundController.updateClientTraffic},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, route := range inboundRoutes {
|
for _, route := range inboundRoutes {
|
||||||
|
|
|
@ -339,3 +339,28 @@ func (a *InboundController) delDepletedClients(c *gin.Context) {
|
||||||
func (a *InboundController) onlines(c *gin.Context) {
|
func (a *InboundController) onlines(c *gin.Context) {
|
||||||
jsonObj(c, a.inboundService.GetOnlineClients(), nil)
|
jsonObj(c, a.inboundService.GetOnlineClients(), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *InboundController) updateClientTraffic(c *gin.Context) {
|
||||||
|
email := c.Param("email")
|
||||||
|
|
||||||
|
// Define the request structure for traffic update
|
||||||
|
type TrafficUpdateRequest struct {
|
||||||
|
Upload int64 `json:"upload"`
|
||||||
|
Download int64 `json:"download"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var request TrafficUpdateRequest
|
||||||
|
err := c.ShouldBindJSON(&request)
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = a.inboundService.UpdateClientTrafficByEmail(email, request.Upload, request.Download)
|
||||||
|
if err != nil {
|
||||||
|
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundClientUpdateSuccess"), nil)
|
||||||
|
}
|
||||||
|
|
|
@ -1785,6 +1785,21 @@ func (s *InboundService) GetClientTrafficByEmail(email string) (traffic *xray.Cl
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *InboundService) UpdateClientTrafficByEmail(email string, upload int64, download int64) error {
|
||||||
|
db := database.GetDB()
|
||||||
|
|
||||||
|
result := db.Model(xray.ClientTraffic{}).
|
||||||
|
Where("email = ?", email).
|
||||||
|
Updates(map[string]any{"up": upload, "down": download})
|
||||||
|
|
||||||
|
err := result.Error
|
||||||
|
if err != nil {
|
||||||
|
logger.Warningf("Error updating ClientTraffic with email %s: %v", email, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *InboundService) GetClientTrafficByID(id string) ([]xray.ClientTraffic, error) {
|
func (s *InboundService) GetClientTrafficByID(id string) ([]xray.ClientTraffic, error) {
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
var traffics []xray.ClientTraffic
|
var traffics []xray.ClientTraffic
|
||||||
|
|
Loading…
Reference in a new issue