mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-13 23:01:00 +00:00
fix(sub): deduplicate settings.clients entries per inbound in subscription output (#5134)
Multi-node sync/import drift can leave the same client twice inside an inbound's legacy settings.clients JSON while the normalized client_inbounds table stays clean (SyncInbound dedupes the rows it writes but never rewrites the JSON). All three subscription builders iterated that JSON verbatim, so every duplicate entry became a duplicate profile in the raw, Clash, and JSON output. Filter and dedupe by email in one shared helper (link generation keys purely on inbound + email, so same-email entries are pure duplicates and dropping them is lossless). The clash/json services' own inboundService copies became unused and are removed.
This commit is contained in:
@@ -8,10 +8,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/logger"
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/util/json_util"
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/util/random"
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/web/service"
|
||||
)
|
||||
|
||||
//go:embed default.json
|
||||
@@ -24,8 +22,7 @@ type SubJsonService struct {
|
||||
finalMask string
|
||||
mux string
|
||||
|
||||
inboundService service.InboundService
|
||||
SubService *SubService
|
||||
SubService *SubService
|
||||
}
|
||||
|
||||
// NewSubJsonService creates a new JSON subscription service with the given configuration.
|
||||
@@ -75,20 +72,15 @@ func (s *SubJsonService) GetJson(subId string, host string) (string, string, err
|
||||
seenEmails := make(map[string]struct{})
|
||||
// Prepare Inbounds
|
||||
for _, inbound := range inbounds {
|
||||
clients, err := s.inboundService.GetClients(inbound)
|
||||
if err != nil {
|
||||
logger.Error("SubJsonService - GetClients: Unable to get clients from inbound")
|
||||
}
|
||||
if clients == nil {
|
||||
clients := s.SubService.matchingClients(inbound, subId)
|
||||
if len(clients) == 0 {
|
||||
continue
|
||||
}
|
||||
s.SubService.projectThroughFallbackMaster(inbound)
|
||||
|
||||
for _, client := range clients {
|
||||
if client.SubID == subId {
|
||||
seenEmails[client.Email] = struct{}{}
|
||||
configArray = append(configArray, s.getConfig(inbound, client, host)...)
|
||||
}
|
||||
seenEmails[client.Email] = struct{}{}
|
||||
configArray = append(configArray, s.getConfig(inbound, client, host)...)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user