mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2025-09-12 13:10:05 +00:00
up
This commit is contained in:
parent
011e0f309a
commit
c5e45144c1
3 changed files with 52 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)
|
||||||
|
}
|
||||||
|
|
|
@ -2060,3 +2060,29 @@ func (s *InboundService) FilterAndSortClientEmails(emails []string) ([]string, [
|
||||||
|
|
||||||
return validEmails, extraEmails, nil
|
return validEmails, extraEmails, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *InboundService) UpdateClientTrafficByEmail(email string, upload int64, download int64) error {
|
||||||
|
db := database.GetDB()
|
||||||
|
|
||||||
|
// Find the client traffic record by email
|
||||||
|
var clientTraffic xray.ClientTraffic
|
||||||
|
err := db.Model(xray.ClientTraffic{}).Where("email = ?", email).First(&clientTraffic).Error
|
||||||
|
if err != nil {
|
||||||
|
if err == gorm.ErrRecordNotFound {
|
||||||
|
return common.NewError("Client with email not found:", email)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the upload and download values
|
||||||
|
clientTraffic.Up = upload
|
||||||
|
clientTraffic.Down = download
|
||||||
|
|
||||||
|
// Save the updated record
|
||||||
|
err = db.Save(&clientTraffic).Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue