From fe4fa9b9e6765c7e05699488aac56e7eeeb68e0d Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Fri, 18 Jul 2025 19:45:55 +0200 Subject: [PATCH] fix client links #670 #671 --- service/client.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/service/client.go b/service/client.go index 90c2256..1e771ba 100644 --- a/service/client.go +++ b/service/client.go @@ -55,7 +55,7 @@ func (s *ClientService) Save(tx *gorm.DB, act string, data json.RawMessage, host if err != nil { return nil, err } - err = s.updateLinksWithFixedInbounds(tx, []*model.Client{&client}, inboundIds, hostname) + err = s.updateLinksWithFixedInbounds(tx, []*model.Client{&client}, hostname) if err != nil { return nil, err } @@ -81,11 +81,7 @@ func (s *ClientService) Save(tx *gorm.DB, act string, data json.RawMessage, host if err != nil { return nil, err } - err = json.Unmarshal(clients[0].Inbounds, &inboundIds) - if err != nil { - return nil, err - } - err = s.updateLinksWithFixedInbounds(tx, clients, inboundIds, hostname) + err = s.updateLinksWithFixedInbounds(tx, clients, hostname) if err != nil { return nil, err } @@ -119,13 +115,19 @@ func (s *ClientService) Save(tx *gorm.DB, act string, data json.RawMessage, host return inboundIds, nil } -func (s *ClientService) updateLinksWithFixedInbounds(tx *gorm.DB, clients []*model.Client, inbounIds []uint, hostname string) error { +func (s *ClientService) updateLinksWithFixedInbounds(tx *gorm.DB, clients []*model.Client, hostname string) error { var err error var inbounds []model.Inbound + var inboundIds []uint + + err = json.Unmarshal(clients[0].Inbounds, &inboundIds) + if err != nil { + return err + } // Zero inbounds means removing local links only - if len(inbounIds) > 0 { - err = tx.Model(model.Inbound{}).Preload("Tls").Where("id in ? and type in ?", inbounIds, util.InboundTypeWithLink).Find(&inbounds).Error + if len(inboundIds) > 0 { + err = tx.Model(model.Inbound{}).Preload("Tls").Where("id in ? and type in ?", inboundIds, util.InboundTypeWithLink).Find(&inbounds).Error if err != nil { return err }