Release 3X-UI for Docker / build (push) Canceled after 0s
Release 3X-UI / build (386) (push) Canceled after 0s
Release 3X-UI / build (amd64) (push) Canceled after 0s
Release 3X-UI / build (arm64) (push) Canceled after 0s
Release 3X-UI / build (armv5) (push) Canceled after 0s
Release 3X-UI / build (armv6) (push) Canceled after 0s
Release 3X-UI / build (armv7) (push) Canceled after 0s
Release 3X-UI / build (s390x) (push) Canceled after 0s
Release 3X-UI / Build for Windows (amd64) (push) Canceled after 0s
Release 3X-UI / Publish rolling dev release (push) Canceled after 0s
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
|
|
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
|
"github.com/mhsanaei/3x-ui/v3/internal/util/common"
|
|
)
|
|
|
|
func ParseInboundSettingsClients(settings string) ([]model.Client, error) {
|
|
trimmed := strings.TrimSpace(settings)
|
|
if trimmed == "" || trimmed == "null" {
|
|
return nil, common.NewError("inbound settings is empty")
|
|
}
|
|
|
|
var payload struct {
|
|
Clients json.RawMessage `json:"clients"`
|
|
}
|
|
if err := json.Unmarshal([]byte(trimmed), &payload); err != nil {
|
|
return nil, err
|
|
}
|
|
if len(payload.Clients) == 0 || string(payload.Clients) == "null" {
|
|
return nil, nil
|
|
}
|
|
|
|
var clients []model.Client
|
|
if err := json.Unmarshal(payload.Clients, &clients); err != nil {
|
|
return nil, err
|
|
}
|
|
return clients, nil
|
|
}
|
|
|
|
// settingsEntriesToClients decodes the wire entries a caller has already
|
|
// stamped, so a delta carries the persisted created_at / updated_at / subId
|
|
// rather than the pre-stamp values the request was parsed into.
|
|
func settingsEntriesToClients(entries []any) ([]model.Client, error) {
|
|
if len(entries) == 0 {
|
|
return nil, nil
|
|
}
|
|
raw, err := json.Marshal(entries)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var clients []model.Client
|
|
if err := json.Unmarshal(raw, &clients); err != nil {
|
|
return nil, err
|
|
}
|
|
return clients, nil
|
|
}
|