diff options
| author | MHSanaei <ho3ein.sanaei@gmail.com> | 2023-04-27 18:35:36 +0300 |
|---|---|---|
| committer | MHSanaei <ho3ein.sanaei@gmail.com> | 2023-04-27 18:35:36 +0300 |
| commit | 103a26edb6990338249c2f33f1a68d83b971a070 (patch) | |
| tree | ac21d9b903bdf7d1e58c0197b0969a9eafd57bc9 | |
| parent | 7419592626c737e4a39f8ca9a11b28a6dc97034a (diff) | |
[migrate] remove orphaned traffics
Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
| -rw-r--r-- | web/service/inbound.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/web/service/inbound.go b/web/service/inbound.go index 64e54af7..b4549309 100644 --- a/web/service/inbound.go +++ b/web/service/inbound.go @@ -912,6 +912,8 @@ func (s *InboundService) SearchInbounds(query string) ([]*model.Inbound, error) func (s *InboundService) MigrationRequirements() { db := database.GetDB() + + // Fix inbounds based problems var inbounds []*model.Inbound err := db.Model(model.Inbound{}).Where("protocol IN (?)", []string{"vmess", "vless", "trojan"}).Find(&inbounds).Error if err != nil && err != gorm.ErrRecordNotFound { @@ -922,6 +924,7 @@ func (s *InboundService) MigrationRequirements() { json.Unmarshal([]byte(inbounds[inbound_index].Settings), &settings) clients, ok := settings["clients"].([]interface{}) if ok { + // Fix Clinet configuration problems var newClients []interface{} for client_index := range clients { c := clients[client_index].(map[string]interface{}) @@ -947,6 +950,7 @@ func (s *InboundService) MigrationRequirements() { inbounds[inbound_index].Settings = string(modifiedSettings) } + // Add client traffic row for all clients which has email modelClients, err := s.getClients(inbounds[inbound_index]) if err != nil { return @@ -962,4 +966,7 @@ func (s *InboundService) MigrationRequirements() { } } db.Save(inbounds) + + // Remove orphaned traffics + db.Where("inbound_id = 0").Delete(xray.ClientTraffic{}) } |
