diff --git a/web/controller/xray_setting.go b/web/controller/xray_setting.go index 430cc77b..28f55b54 100644 --- a/web/controller/xray_setting.go +++ b/web/controller/xray_setting.go @@ -29,6 +29,7 @@ func (a *XraySettingController) initRouter(g *gin.RouterGroup) { g.GET("/getDefaultJsonConfig", a.getDefaultXrayConfig) g.POST("/warp/:action", a.warp) g.GET("/getOutboundsTraffic", a.getOutboundsTraffic) + g.POST("/resetOutboundsTraffic", a.resetOutboundsTraffic) } func (a *XraySettingController) getXraySetting(c *gin.Context) { @@ -95,3 +96,13 @@ func (a *XraySettingController) getOutboundsTraffic(c *gin.Context) { } jsonObj(c, outboundsTraffic, nil) } + +func (a *XraySettingController) resetOutboundsTraffic(c *gin.Context) { + tag := c.PostForm("tag") + err := a.OutboundService.ResetOutboundTraffic(tag) + if err != nil { + jsonMsg(c, "Error in reset outbound traffics", err) + return + } + jsonObj(c, "", nil) +} diff --git a/web/html/xui/xray.html b/web/html/xui/xray.html index a144c766..871631e0 100644 --- a/web/html/xui/xray.html +++ b/web/html/xui/xray.html @@ -385,11 +385,13 @@ - {{ i18n "pages.xray.outbound.addOutbound" }} + {{ i18n + "pages.xray.outbound.addOutbound" }} WARP - + + {{ i18n "edit" }} + + + {{ i18n "pages.inbounds.resetTraffic"}} + + {{ i18n "delete"}} @@ -947,6 +954,16 @@ this.refreshing = false; } }, + async resetOutboundTraffic(index) { + let tag = "-alltags-"; + if (index >= 0) { + tag = this.outboundData[index].tag ? this.outboundData[index].tag : "" + } + const msg = await HttpUtil.post("/panel/xray/resetOutboundsTraffic", { tag: tag }); + if (msg.success) { + await this.refreshOutboundTraffic(); + } + }, addBalancer() { balancerModal.show({ title: '{{ i18n "pages.xray.balancer.addBalancer"}}', diff --git a/web/service/outbound.go b/web/service/outbound.go index dc0e0742..244d7a14 100644 --- a/web/service/outbound.go +++ b/web/service/outbound.go @@ -78,3 +78,25 @@ func (s *OutboundService) GetOutboundsTraffic() ([]*model.OutboundTraffics, erro return traffics, nil } + +func (s *OutboundService) ResetOutboundTraffic(tag string) error { + db := database.GetDB() + + whereText := "tag " + if tag == "-alltags-" { + whereText += " <> ?" + } else { + whereText += " = ?" + } + + result := db.Model(model.OutboundTraffics{}). + Where(whereText, tag). + Updates(map[string]interface{}{"up": 0, "down": 0, "total": 0}) + + err := result.Error + if err != nil { + return err + } + + return nil +}