@@ -50,6 +50,7 @@ var endpointParsers = map[string]EndpointParserFunc{
5050 "wireguard://" : AWGSingbox ,
5151 "warp://" : WarpSingbox ,
5252 "awg://" : AWGSingbox ,
53+ "[Interface]" : AWGSingboxTxt ,
5354}
5455var xrayConfigTypes = map [string ]ParserFunc {
5556 "vmess://" : VmessXray ,
@@ -124,70 +125,65 @@ func processSingleConfig(config string, useXrayWhenPossible bool) (outend *OutEn
124125 // json.MarshalIndent(configSingbox, "", " ")
125126 return outend , nil
126127}
128+
127129func GenerateConfigLite (input string , useXrayWhenPossible bool ) (* option.Options , error ) {
128130
129- configArray := strings . Split ( strings . ReplaceAll ( input , " \r " , " \n " ), " \n " )
131+ configArray := expandDecodedConfig ( input )
130132
131133 var outbounds []T.Outbound
132134 var endpoints []T.Endpoint
133135 counter := 0
134- if strings .Contains (input , "[Interface]" ) {
135- end , err := AWGSingboxTxt (input )
136- if err != nil {
137- return nil , err
138- }
139- endpoints = append (endpoints , * end )
140- } else {
141- for _ , config := range configArray {
142- if len (config ) < 5 || config [0 ] == '#' || config [0 ] == '/' {
143- continue
144- }
145- detourTag := ""
146136
147- chains := strings .Split (config , " -> " )
148- for i := len (chains ) - 1 ; i >= 0 ; i -- {
149- chain1 := chains [i ]
150-
151- // fmt.Printf("%s", chain)
152- chain , _ := decodeBase64IfNeeded (chain1 )
153- outend , err := processSingleConfig (chain , useXrayWhenPossible )
137+ for _ , config := range configArray {
138+ if len (config ) < 5 || config [0 ] == '#' || config [0 ] == '/' {
139+ continue
140+ }
141+ detourTag := ""
154142
155- if err != nil {
156- fmt .Fprintf (os .Stderr , "Error in %s \n %v\n " , config , err )
143+ chains := strings .Split (config , " -> " )
144+ for i := len (chains ) - 1 ; i >= 0 ; i -- {
145+ chain1 := chains [i ]
157146
158- continue
159- }
147+ // fmt.Printf("%s", chain)
148+ chain , _ := decodeBase64IfNeeded (chain1 )
149+ outend , err := processSingleConfig (chain , useXrayWhenPossible )
160150
161- if outend .outbound != nil {
162- outend .outbound .Tag += " § " + strconv .Itoa (counter )
163- if dialerOpt , ok := outend .outbound .Options .(T.DialerOptionsWrapper ); ok {
164- d := dialerOpt .TakeDialerOptions ()
165- d .Detour = detourTag
166- dialerOpt .ReplaceDialerOptions (d )
167- }
151+ if err != nil {
152+ fmt .Fprintf (os .Stderr , "Error in %s \n %v\n " , config , err )
168153
169- detourTag = outend . outbound . Tag
170- outbounds = append ( outbounds , * outend . outbound )
154+ continue
155+ }
171156
172- } else if outend .endpoint != nil {
173- outend .endpoint .Tag += " § " + strconv .Itoa (counter )
174- if dialerOpt , ok := outend .endpoint .Options .(T.DialerOptionsWrapper ); ok {
175- d := dialerOpt .TakeDialerOptions ()
176- d .Detour = detourTag
177- dialerOpt .ReplaceDialerOptions (d )
178- }
157+ if outend .outbound != nil {
158+ outend .outbound .Tag += " § " + strconv .Itoa (counter )
159+ if dialerOpt , ok := outend .outbound .Options .(T.DialerOptionsWrapper ); ok {
160+ d := dialerOpt .TakeDialerOptions ()
161+ d .Detour = detourTag
162+ dialerOpt .ReplaceDialerOptions (d )
163+ }
179164
180- detourTag = outend .endpoint .Tag
181- endpoints = append (endpoints , * outend .endpoint )
165+ detourTag = outend .outbound .Tag
166+ outbounds = append (outbounds , * outend .outbound )
182167
168+ } else if outend .endpoint != nil {
169+ outend .endpoint .Tag += " § " + strconv .Itoa (counter )
170+ if dialerOpt , ok := outend .endpoint .Options .(T.DialerOptionsWrapper ); ok {
171+ d := dialerOpt .TakeDialerOptions ()
172+ d .Detour = detourTag
173+ dialerOpt .ReplaceDialerOptions (d )
183174 }
184175
185- counter += 1
176+ detourTag = outend .endpoint .Tag
177+ endpoints = append (endpoints , * outend .endpoint )
186178
187179 }
188180
181+ counter += 1
182+
189183 }
184+
190185 }
186+
191187 if len (outbounds ) == 0 && len (endpoints ) == 0 {
192188 return nil , E .New ("No outbounds found" )
193189 }
0 commit comments