mirror of
https://github.com/bestnite/sub2sing-box.git
synced 2025-10-28 09:33:57 +00:00
重构部分代码
fix: vless ws 配置缺少 path 字段
This commit is contained in:
@@ -5,43 +5,43 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
model2 "sub2sing-box/model"
|
||||
"sub2sing-box/model"
|
||||
"sub2sing-box/util"
|
||||
)
|
||||
|
||||
func ParseShadowsocks(proxy string) (model2.Proxy, error) {
|
||||
func ParseShadowsocks(proxy string) (model.Outbound, error) {
|
||||
if !strings.HasPrefix(proxy, "ss://") {
|
||||
return model2.Proxy{}, errors.New("invalid ss Url")
|
||||
return model.Outbound{}, errors.New("invalid ss Url")
|
||||
}
|
||||
parts := strings.SplitN(strings.TrimPrefix(proxy, "ss://"), "@", 2)
|
||||
if len(parts) != 2 {
|
||||
return model2.Proxy{}, errors.New("invalid ss Url")
|
||||
return model.Outbound{}, errors.New("invalid ss Url")
|
||||
}
|
||||
if !strings.Contains(parts[0], ":") {
|
||||
decoded, err := util.DecodeBase64(parts[0])
|
||||
if err != nil {
|
||||
return model2.Proxy{}, errors.New("invalid ss Url" + err.Error())
|
||||
return model.Outbound{}, errors.New("invalid ss Url" + err.Error())
|
||||
}
|
||||
parts[0] = decoded
|
||||
}
|
||||
credentials := strings.SplitN(parts[0], ":", 2)
|
||||
if len(credentials) != 2 {
|
||||
return model2.Proxy{}, errors.New("invalid ss Url")
|
||||
return model.Outbound{}, errors.New("invalid ss Url")
|
||||
}
|
||||
serverInfo := strings.SplitN(parts[1], "#", 2)
|
||||
serverAndPort := strings.SplitN(serverInfo[0], ":", 2)
|
||||
if len(serverAndPort) != 2 {
|
||||
return model2.Proxy{}, errors.New("invalid ss Url")
|
||||
return model.Outbound{}, errors.New("invalid ss Url")
|
||||
}
|
||||
port, err := strconv.Atoi(strings.TrimSpace(serverAndPort[1]))
|
||||
if err != nil {
|
||||
return model2.Proxy{}, errors.New("invalid ss Url" + err.Error())
|
||||
return model.Outbound{}, errors.New("invalid ss Url" + err.Error())
|
||||
}
|
||||
remarks := ""
|
||||
if len(serverInfo) == 2 {
|
||||
unescape, err := url.QueryUnescape(serverInfo[1])
|
||||
if err != nil {
|
||||
return model2.Proxy{}, errors.New("invalid ss Url" + err.Error())
|
||||
return model.Outbound{}, errors.New("invalid ss Url" + err.Error())
|
||||
}
|
||||
remarks = strings.TrimSpace(unescape)
|
||||
} else {
|
||||
@@ -50,14 +50,16 @@ func ParseShadowsocks(proxy string) (model2.Proxy, error) {
|
||||
method := credentials[0]
|
||||
password := credentials[1]
|
||||
server := strings.TrimSpace(serverAndPort[0])
|
||||
result := model2.Proxy{
|
||||
result := model.Outbound{
|
||||
Type: "shadowsocks",
|
||||
Tag: remarks,
|
||||
Shadowsocks: model2.Shadowsocks{
|
||||
Method: method,
|
||||
Password: password,
|
||||
Server: server,
|
||||
ServerPort: uint16(port),
|
||||
ShadowsocksOptions: model.ShadowsocksOutboundOptions{
|
||||
ServerOptions: model.ServerOptions{
|
||||
Server: server,
|
||||
ServerPort: uint16(port),
|
||||
},
|
||||
Method: method,
|
||||
Password: password,
|
||||
},
|
||||
}
|
||||
return result, nil
|
||||
|
||||
Reference in New Issue
Block a user