Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'web/service/inbound.go')
-rw-r--r--web/service/inbound.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/web/service/inbound.go b/web/service/inbound.go
index fce01634..f2646dbb 100644
--- a/web/service/inbound.go
+++ b/web/service/inbound.go
@@ -3,6 +3,7 @@ package service
import (
"encoding/json"
"fmt"
+ "sort"
"strconv"
"strings"
"time"
@@ -2025,3 +2026,37 @@ func (s *InboundService) MigrateDB() {
func (s *InboundService) GetOnlineClients() []string {
return p.GetOnlineClients()
}
+
+func (s *InboundService) FilterAndSortClientEmails(emails []string) ([]string, []string, error) {
+ db := database.GetDB()
+
+ // Step 1: Get ClientTraffic records for emails in the input list
+ var clients []xray.ClientTraffic
+ err := db.Where("email IN ?", emails).Find(&clients).Error
+ if err != nil && err != gorm.ErrRecordNotFound {
+ return nil, nil, err
+ }
+
+ // Step 2: Sort clients by (Up + Down) descending
+ sort.Slice(clients, func(i, j int) bool {
+ return (clients[i].Up + clients[i].Down) > (clients[j].Up + clients[j].Down)
+ })
+
+ // Step 3: Extract sorted valid emails and track found ones
+ validEmails := make([]string, 0, len(clients))
+ found := make(map[string]bool)
+ for _, client := range clients {
+ validEmails = append(validEmails, client.Email)
+ found[client.Email] = true
+ }
+
+ // Step 4: Identify emails that were not found in the database
+ extraEmails := make([]string, 0)
+ for _, email := range emails {
+ if !found[email] {
+ extraEmails = append(extraEmails, email)
+ }
+ }
+
+ return validEmails, extraEmails, nil
+}