1
0
mirror of https://github.com/nitezs/sub2sing-box.git synced 2024-12-23 15:14:43 -05:00

🎨 Modify some code

This commit is contained in:
Nite07 2024-04-23 14:41:14 +08:00
parent acf547f173
commit 0456c8f802
7 changed files with 45 additions and 26 deletions

View File

@ -35,7 +35,11 @@ func ParseHysteria(proxy string) (model.Outbound, error) {
port, err := ParsePort(portStr)
if err != nil {
return model.Outbound{}, err
return model.Outbound{}, &ParseError{
Type: ErrInvalidPort,
Message: err.Error(),
Raw: proxy,
}
}
params, err := url.ParseQuery(urlParts[1])

View File

@ -52,7 +52,11 @@ func ParseHysteria2(proxy string) (model.Outbound, error) {
port, err := ParsePort(portStr)
if err != nil {
return model.Outbound{}, err
return model.Outbound{}, &ParseError{
Type: ErrInvalidPort,
Message: err.Error(),
Raw: proxy,
}
}
params, err := url.ParseQuery(paramStr)
@ -74,7 +78,7 @@ func ParseHysteria2(proxy string) (model.Outbound, error) {
Hysteria2Options: model.Hysteria2OutboundOptions{
ServerOptions: model.ServerOptions{
Server: server,
ServerPort: uint16(port),
ServerPort: port,
},
Password: password,
Obfs: &model.Hysteria2Obfs{

View File

@ -1,6 +1,7 @@
package parser
import (
"errors"
"strconv"
)
@ -8,16 +9,10 @@ func ParsePort(portStr string) (uint16, error) {
port, err := strconv.Atoi(portStr)
if err != nil {
return 0, &ParseError{
Type: ErrInvalidPort,
Message: portStr,
}
return 0, err
}
if port < 1 || port > 65535 {
return 0, &ParseError{
Type: ErrInvalidPort,
Message: portStr,
}
return 0, errors.New("invaild port range")
}
return uint16(port), nil
}

View File

@ -57,7 +57,11 @@ func ParseShadowsocks(proxy string) (model.Outbound, error) {
}
port, err := ParsePort(portStr)
if err != nil {
return model.Outbound{}, err
return model.Outbound{}, &ParseError{
Type: ErrInvalidPort,
Message: err.Error(),
Raw: proxy,
}
}
var remarks string

View File

@ -54,7 +54,11 @@ func ParseTrojan(proxy string) (model.Outbound, error) {
port, err := ParsePort(portStr)
if err != nil {
return model.Outbound{}, err
return model.Outbound{}, &ParseError{
Type: ErrInvalidPort,
Message: err.Error(),
Raw: proxy,
}
}
remarks := ""
@ -98,7 +102,7 @@ func ParseTrojan(proxy string) (model.Outbound, error) {
}
}
if params.Get("security") == "reality" {
if security == "reality" {
result.TrojanOptions.OutboundTLSOptionsContainer = model.OutboundTLSOptionsContainer{
TLS: &model.OutboundTLSOptions{
Enabled: true,
@ -116,7 +120,7 @@ func ParseTrojan(proxy string) (model.Outbound, error) {
}
}
if params.Get("type") == "ws" {
if network == "ws" {
result.TrojanOptions.Transport = &model.V2RayTransportOptions{
Type: "ws",
WebsocketOptions: model.V2RayWebsocketOptions{
@ -128,24 +132,24 @@ func ParseTrojan(proxy string) (model.Outbound, error) {
}
}
if params.Get("type") == "http" {
if network == "http" {
result.TrojanOptions.Transport = &model.V2RayTransportOptions{
Type: "http",
HTTPOptions: model.V2RayHTTPOptions{
Host: []string{host},
Path: params.Get("path"),
Path: path,
},
}
}
if params.Get("type") == "quic" {
if network == "quic" {
result.TrojanOptions.Transport = &model.V2RayTransportOptions{
Type: "quic",
QUICOptions: model.V2RayQUICOptions{},
}
}
if params.Get("type") == "grpc" {
if network == "grpc" {
result.TrojanOptions.Transport = &model.V2RayTransportOptions{
Type: "grpc",
GRPCOptions: model.V2RayGRPCOptions{

View File

@ -42,7 +42,11 @@ func ParseVless(proxy string) (model.Outbound, error) {
server, portStr := serverAndPort[0], serverAndPort[1]
port, err := ParsePort(portStr)
if err != nil {
return model.Outbound{}, err
return model.Outbound{}, &ParseError{
Type: ErrInvalidPort,
Message: err.Error(),
Raw: proxy,
}
}
params, err := url.ParseQuery(serverAndPortAndParams[1])
@ -76,7 +80,7 @@ func ParseVless(proxy string) (model.Outbound, error) {
}
uuid := strings.TrimSpace(urlParts[0])
flow, security, alpnStr, sni, insecure, fp, pbk, sid, path, host, serviceName := params.Get("flow"), params.Get("security"), params.Get("alpn"), params.Get("sni"), params.Get("allowInsecure"), params.Get("fp"), params.Get("pbk"), params.Get("sid"), params.Get("path"), params.Get("host"), params.Get("serviceName")
flow, security, alpnStr, sni, insecure, fp, pbk, sid, path, host, serviceName, _type := params.Get("flow"), params.Get("security"), params.Get("alpn"), params.Get("sni"), params.Get("allowInsecure"), params.Get("fp"), params.Get("pbk"), params.Get("sid"), params.Get("path"), params.Get("host"), params.Get("serviceName"), params.Get("type")
enableUTLS := fp != ""
insecureBool := insecure == "1"
@ -123,7 +127,7 @@ func ParseVless(proxy string) (model.Outbound, error) {
}
}
if params.Get("type") == "ws" {
if _type == "ws" {
result.VLESSOptions.Transport = &model.V2RayTransportOptions{
Type: "ws",
WebsocketOptions: model.V2RayWebsocketOptions{
@ -138,14 +142,14 @@ func ParseVless(proxy string) (model.Outbound, error) {
}
}
if params.Get("type") == "quic" {
if _type == "quic" {
result.VLESSOptions.Transport = &model.V2RayTransportOptions{
Type: "quic",
QUICOptions: model.V2RayQUICOptions{},
}
}
if params.Get("type") == "grpc" {
if _type == "grpc" {
result.VLESSOptions.Transport = &model.V2RayTransportOptions{
Type: "grpc",
GRPCOptions: model.V2RayGRPCOptions{
@ -154,7 +158,7 @@ func ParseVless(proxy string) (model.Outbound, error) {
}
}
if params.Get("type") == "http" {
if _type == "http" {
hosts, err := url.QueryUnescape(host)
if err != nil {
return model.Outbound{}, &ParseError{

View File

@ -32,7 +32,11 @@ func ParseVmess(proxy string) (model.Outbound, error) {
case string:
port, err = ParsePort(vmess.Port.(string))
if err != nil {
return model.Outbound{}, err
return model.Outbound{}, &ParseError{
Type: ErrInvalidPort,
Message: err.Error(),
Raw: proxy,
}
}
case float64:
port = uint16(vmess.Port.(float64))