Fix Bug in deleting the client alireza0/x-ui#20

This commit is contained in:
Alireza Ahmadi
2023-03-01 13:57:48 +01:00
parent 40bb9f9864
commit afd369993a
3 changed files with 35 additions and 28 deletions

View File

@@ -258,28 +258,22 @@ func (s *InboundService) AddInboundClient(inbound *model.Inbound) error {
return db.Save(oldInbound).Error
}
func (s *InboundService) DelInboundClient(inboundId int, index int) error {
oldInbound, err := s.GetInbound(inboundId)
if err != nil {
return err
}
settings := map[string][]model.Client{}
json.Unmarshal([]byte(oldInbound.Settings), &settings)
clients := settings["clients"]
email := clients[index].Email
settings["clients"] = append(clients[:index], clients[index+1:]...)
newSetting, err := json.Marshal(settings)
if err != nil {
return err
}
oldInbound.Settings = string(newSetting)
func (s *InboundService) DelInboundClient(inbound *model.Inbound, email string) error {
db := database.GetDB()
err = s.DelClientStat(db, email)
err := s.DelClientStat(db, email)
if err != nil {
logger.Error("Delete stats Data Error")
return err
}
oldInbound, err := s.GetInbound(inbound.Id)
if err != nil {
logger.Error("Load Old Data Error")
return err
}
oldInbound.Settings = inbound.Settings
return db.Save(oldInbound).Error
}