fix: bugs

This commit is contained in:
Hiddify
2024-01-25 23:09:24 +01:00
parent 44e90ba0e0
commit cc4e89445f
5 changed files with 23 additions and 18 deletions

View File

@@ -5,6 +5,7 @@ import (
_ "embed"
"encoding/json"
"fmt"
"os"
"github.com/hiddify/ray2sing/ray2sing"
@@ -23,21 +24,23 @@ func ParseConfig(path string, debug bool) ([]byte, error) {
if err != nil {
return nil, err
}
var jsonObj map[string]interface{}
fmt.Printf("Convert using json\n")
jsonDecoder := json.NewDecoder(SJ.NewCommentFilter(bytes.NewReader(content)))
if err := jsonDecoder.Decode(&jsonObj); err == nil {
if jsonObj["outbounds"] == nil {
return nil, fmt.Errorf("[SingboxParser] no outbounds found")
}
return validateResult(content, "SingboxParser")
newContent, _ := json.MarshalIndent(jsonObj, "", " ")
return validateResult(newContent, "SingboxParser")
}
fmt.Printf("Convert using v2ray\n")
v2rayStr, err := ray2sing.Ray2Singbox(string(content))
if err == nil {
return validateResult([]byte(v2rayStr), "V2rayParser")
}
fmt.Printf("Convert using clash\n")
clashObj := clash.Clash{}
if err := yaml.Unmarshal(content, &clashObj); err == nil && clashObj.Proxies != nil {
if len(clashObj.Proxies) == 0 {