make ConvertsV2Ray more robust (#349)
* make ConvertsV2Ray more robust * add log * fix
This commit is contained in:
parent
39394e49ae
commit
023a96a6d3
4 changed files with 22 additions and 3 deletions
|
@ -165,6 +165,7 @@ func (gb *GroupBase) GetProxies(touch bool) []C.Proxy {
|
||||||
for i := range gb.excludeTypeArray {
|
for i := range gb.excludeTypeArray {
|
||||||
if strings.EqualFold(mType, gb.excludeTypeArray[i]) {
|
if strings.EqualFold(mType, gb.excludeTypeArray[i]) {
|
||||||
flag = true
|
flag = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -301,6 +301,7 @@ func proxiesParseAndFilter(filter string, excludeFilter string, excludeTypeArray
|
||||||
for i := range excludeTypeArray {
|
for i := range excludeTypeArray {
|
||||||
if strings.EqualFold(pType, excludeTypeArray[i]) {
|
if strings.EqualFold(pType, excludeTypeArray[i]) {
|
||||||
flag = true
|
flag = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/Dreamacro/clash/log"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -120,7 +121,11 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
|
||||||
}
|
}
|
||||||
query := urlVLess.Query()
|
query := urlVLess.Query()
|
||||||
vless := make(map[string]any, 20)
|
vless := make(map[string]any, 20)
|
||||||
handleVShareLink(names, urlVLess, scheme, vless)
|
err = handleVShareLink(names, urlVLess, scheme, vless)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnln("error:%s line:%s", err.Error(), line)
|
||||||
|
continue
|
||||||
|
}
|
||||||
if flow := query.Get("flow"); flow != "" {
|
if flow := query.Get("flow"); flow != "" {
|
||||||
vless["flow"] = strings.ToLower(flow)
|
vless["flow"] = strings.ToLower(flow)
|
||||||
}
|
}
|
||||||
|
@ -138,7 +143,11 @@ func ConvertsV2Ray(buf []byte) ([]map[string]any, error) {
|
||||||
}
|
}
|
||||||
query := urlVMess.Query()
|
query := urlVMess.Query()
|
||||||
vmess := make(map[string]any, 20)
|
vmess := make(map[string]any, 20)
|
||||||
handleVShareLink(names, urlVMess, scheme, vmess)
|
err = handleVShareLink(names, urlVMess, scheme, vmess)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnln("error:%s line:%s", err.Error(), line)
|
||||||
|
continue
|
||||||
|
}
|
||||||
vmess["alterId"] = 0
|
vmess["alterId"] = 0
|
||||||
vmess["cipher"] = "auto"
|
vmess["cipher"] = "auto"
|
||||||
if encryption := query.Get("encryption"); encryption != "" {
|
if encryption := query.Get("encryption"); encryption != "" {
|
||||||
|
|
|
@ -1,15 +1,22 @@
|
||||||
package convert
|
package convert
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func handleVShareLink(names map[string]int, url *url.URL, scheme string, proxy map[string]any) {
|
func handleVShareLink(names map[string]int, url *url.URL, scheme string, proxy map[string]any) error {
|
||||||
// Xray VMessAEAD / VLESS share link standard
|
// Xray VMessAEAD / VLESS share link standard
|
||||||
// https://github.com/XTLS/Xray-core/discussions/716
|
// https://github.com/XTLS/Xray-core/discussions/716
|
||||||
query := url.Query()
|
query := url.Query()
|
||||||
proxy["name"] = uniqueName(names, url.Fragment)
|
proxy["name"] = uniqueName(names, url.Fragment)
|
||||||
|
if url.Hostname() == "" {
|
||||||
|
return errors.New("url.Hostname() is empty")
|
||||||
|
}
|
||||||
|
if url.Port() == "" {
|
||||||
|
return errors.New("url.Port() is empty")
|
||||||
|
}
|
||||||
proxy["type"] = scheme
|
proxy["type"] = scheme
|
||||||
proxy["server"] = url.Hostname()
|
proxy["server"] = url.Hostname()
|
||||||
proxy["port"] = url.Port()
|
proxy["port"] = url.Port()
|
||||||
|
@ -94,4 +101,5 @@ func handleVShareLink(names map[string]int, url *url.URL, scheme string, proxy m
|
||||||
grpcOpts["grpc-service-name"] = query.Get("serviceName")
|
grpcOpts["grpc-service-name"] = query.Get("serviceName")
|
||||||
proxy["grpc-opts"] = grpcOpts
|
proxy["grpc-opts"] = grpcOpts
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue