From eda8be601f56c788b1ad176c7d68d8e2ce22c7ca Mon Sep 17 00:00:00 2001 From: RPRX <63339210+RPRX@users.noreply.github.com> Date: Tue, 9 Sep 2025 12:37:22 +0000 Subject: [PATCH] Fuck vnext json nesting --- infra/conf/vless.go | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/infra/conf/vless.go b/infra/conf/vless.go index fb4ee464..aa410e5c 100644 --- a/infra/conf/vless.go +++ b/infra/conf/vless.go @@ -203,13 +203,30 @@ type VLessOutboundVnext struct { } type VLessOutboundConfig struct { - Vnext []*VLessOutboundVnext `json:"vnext"` + Address *Address `json:"address"` + Port uint16 `json:"port"` + Level uint32 `json:"level"` + Email string `json:"email"` + Id string `json:"id"` + Flow string `json:"flow"` + Seed string `json:"seed"` + Encryption string `json:"encryption"` + Reverse *vless.Reverse `json:"reverse"` + Vnext []*VLessOutboundVnext `json:"vnext"` } // Build implements Buildable func (c *VLessOutboundConfig) Build() (proto.Message, error) { config := new(outbound.Config) - + if c.Address != nil { + c.Vnext = []*VLessOutboundVnext{ + { + Address: c.Address, + Port: c.Port, + Users: []json.RawMessage{{}}, + }, + } + } if len(c.Vnext) != 1 { return nil, errors.New(`VLESS settings: "vnext" should have one and only one member`) } @@ -228,12 +245,25 @@ func (c *VLessOutboundConfig) Build() (proto.Message, error) { } for idx, rawUser := range rec.Users { user := new(protocol.User) - if err := json.Unmarshal(rawUser, user); err != nil { - return nil, errors.New(`VLESS users: invalid user`).Base(err) + if c.Address != nil { + user.Level = c.Level + user.Email = c.Email + } else { + if err := json.Unmarshal(rawUser, user); err != nil { + return nil, errors.New(`VLESS users: invalid user`).Base(err) + } } account := new(vless.Account) - if err := json.Unmarshal(rawUser, account); err != nil { - return nil, errors.New(`VLESS users: invalid user`).Base(err) + if c.Address != nil { + account.Id = c.Id + account.Flow = c.Flow + //account.Seed = c.Seed + account.Encryption = c.Encryption + account.Reverse = c.Reverse + } else { + if err := json.Unmarshal(rawUser, account); err != nil { + return nil, errors.New(`VLESS users: invalid user`).Base(err) + } } u, err := uuid.ParseString(account.Id)