fix: comprehensive bug fixes - wrong toast messages, duplicate calls, hardcoded strings

Bugs Fixed (17 total across 3 files):

== web/controller/inbound.go ==
1-11. Fix 11 error paths showing success toast messages:
  - addInbound: inboundCreateSuccess → somethingWentWrong
  - delInbound: inboundDeleteSuccess → somethingWentWrong
  - updateInbound (2x): inboundUpdateSuccess → somethingWentWrong
  - clearClientIps: updateSuccess → somethingWentWrong
  - addInboundClient: inboundUpdateSuccess → somethingWentWrong
  - delInboundClient: inboundUpdateSuccess → somethingWentWrong
  - updateInboundClient: inboundUpdateSuccess → somethingWentWrong
  - resetClientTraffic: inboundUpdateSuccess → somethingWentWrong
  - resetAllClientTraffics: inboundUpdateSuccess → somethingWentWrong
  - delDepletedClients: inboundUpdateSuccess → somethingWentWrong
12. Remove duplicate xrayService.SetToNeedRestart() in resetAllTraffics
13. Remove duplicate xrayService.SetToNeedRestart() in resetAllClientTraffics
14-16. Replace hardcoded strings in delInboundClientByEmail with I18n

== web/controller/server.go ==
17. Replace hardcoded strings with I18n in:
  - getNewUUID, getNewmlkem768, getNewEchCert

== web/service/inbound.go ==
18. Remove duplicate 'User not found' nested if-check in disableInvalidClients

Related to PR #3974 (same class of bugs extended to all error paths)
This commit is contained in:
Bug Fix Bot 2026-03-28 15:42:08 +08:00
parent 38d87230d3
commit 71dc7d983d
3 changed files with 22 additions and 28 deletions

View file

@ -107,7 +107,7 @@ func (a *InboundController) addInbound(c *gin.Context) {
inbound := &model.Inbound{}
err := c.ShouldBind(inbound)
if err != nil {
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundCreateSuccess"), err)
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
user := session.GetLoginUser(c)
@ -136,7 +136,7 @@ func (a *InboundController) addInbound(c *gin.Context) {
func (a *InboundController) delInbound(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundDeleteSuccess"), err)
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
needRestart, err := a.inboundService.DelInbound(id)
@ -158,7 +158,7 @@ func (a *InboundController) delInbound(c *gin.Context) {
func (a *InboundController) updateInbound(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
inbound := &model.Inbound{
@ -166,7 +166,7 @@ func (a *InboundController) updateInbound(c *gin.Context) {
}
err = c.ShouldBind(inbound)
if err != nil {
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
inbound, needRestart, err := a.inboundService.UpdateInbound(inbound)
@ -234,7 +234,7 @@ func (a *InboundController) clearClientIps(c *gin.Context) {
err := a.inboundService.ClearClientIps(email)
if err != nil {
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.updateSuccess"), err)
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.logCleanSuccess"), nil)
@ -245,7 +245,7 @@ func (a *InboundController) addInboundClient(c *gin.Context) {
data := &model.Inbound{}
err := c.ShouldBind(data)
if err != nil {
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
@ -264,7 +264,7 @@ func (a *InboundController) addInboundClient(c *gin.Context) {
func (a *InboundController) delInboundClient(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
clientId := c.Param("clientId")
@ -287,7 +287,7 @@ func (a *InboundController) updateInboundClient(c *gin.Context) {
inbound := &model.Inbound{}
err := c.ShouldBind(inbound)
if err != nil {
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
@ -306,7 +306,7 @@ func (a *InboundController) updateInboundClient(c *gin.Context) {
func (a *InboundController) resetClientTraffic(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
email := c.Param("email")
@ -328,9 +328,8 @@ func (a *InboundController) resetAllTraffics(c *gin.Context) {
if err != nil {
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
} else {
a.xrayService.SetToNeedRestart()
}
a.xrayService.SetToNeedRestart()
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.resetAllTrafficSuccess"), nil)
}
@ -338,7 +337,7 @@ func (a *InboundController) resetAllTraffics(c *gin.Context) {
func (a *InboundController) resetAllClientTraffics(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
@ -346,9 +345,8 @@ func (a *InboundController) resetAllClientTraffics(c *gin.Context) {
if err != nil {
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
} else {
a.xrayService.SetToNeedRestart()
}
a.xrayService.SetToNeedRestart()
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.resetAllClientTrafficSuccess"), nil)
}
@ -386,7 +384,7 @@ func (a *InboundController) importInbound(c *gin.Context) {
func (a *InboundController) delDepletedClients(c *gin.Context) {
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
err = a.inboundService.DelDepletedClients(id)
@ -421,7 +419,7 @@ func (a *InboundController) updateClientTraffic(c *gin.Context) {
var request TrafficUpdateRequest
err := c.ShouldBindJSON(&request)
if err != nil {
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
@ -438,18 +436,18 @@ func (a *InboundController) updateClientTraffic(c *gin.Context) {
func (a *InboundController) delInboundClientByEmail(c *gin.Context) {
inboundId, err := strconv.Atoi(c.Param("id"))
if err != nil {
jsonMsg(c, "Invalid inbound ID", err)
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
email := c.Param("email")
needRestart, err := a.inboundService.DelInboundClientByEmail(inboundId, email)
if err != nil {
jsonMsg(c, "Failed to delete client by email", err)
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
jsonMsg(c, "Client deleted successfully", nil)
jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundClientDeleteSuccess"), nil)
if needRestart {
a.xrayService.SetToNeedRestart()
}

View file

@ -325,7 +325,7 @@ func (a *ServerController) getNewEchCert(c *gin.Context) {
sni := c.PostForm("sni")
cert, err := a.serverService.GetNewEchCert(sni)
if err != nil {
jsonMsg(c, "get ech certificate", err)
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
jsonObj(c, cert, nil)
@ -345,7 +345,7 @@ func (a *ServerController) getNewVlessEnc(c *gin.Context) {
func (a *ServerController) getNewUUID(c *gin.Context) {
uuidResp, err := a.serverService.GetNewUUID()
if err != nil {
jsonMsg(c, "Failed to generate UUID", err)
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
@ -356,7 +356,7 @@ func (a *ServerController) getNewUUID(c *gin.Context) {
func (a *ServerController) getNewmlkem768(c *gin.Context) {
out, err := a.serverService.GetNewmlkem768()
if err != nil {
jsonMsg(c, "Failed to generate mlkem768 keys", err)
jsonMsg(c, I18nWeb(c, "somethingWentWrong"), err)
return
}
jsonObj(c, out, nil)

View file

@ -1280,12 +1280,8 @@ func (s *InboundService) disableInvalidClients(tx *gorm.DB) (bool, int64, error)
if strings.Contains(err1.Error(), fmt.Sprintf("User %s not found.", result.Email)) {
logger.Debug("User is already disabled. Nothing to do more...")
} else {
if strings.Contains(err1.Error(), fmt.Sprintf("User %s not found.", result.Email)) {
logger.Debug("User is already disabled. Nothing to do more...")
} else {
logger.Debug("Error in disabling client by api:", err1)
needRestart = true
}
logger.Debug("Error in disabling client by api:", err1)
needRestart = true
}
}
}