From 5395417a31343e7d3bfce78adce06a3cdca376cf Mon Sep 17 00:00:00 2001 From: Nite07 Date: Sun, 4 Aug 2024 17:46:11 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Remove=20redundant=20field?= =?UTF-8?q?s=20from=20results?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/convert.go | 5 ++++- parser/hysteria2.go | 24 +++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/common/convert.go b/common/convert.go index b763c89..b820fdb 100644 --- a/common/convert.go +++ b/common/convert.go @@ -260,7 +260,10 @@ func ConvertSubscriptionsToSProxy(urls []string) ([]model.Outbound, error) { if err != nil { return nil, err } - proxy, err := util.DecodeBase64(data) + proxy := data + if !strings.Contains(data, "://") { + proxy, err = util.DecodeBase64(data) + } if err != nil { return nil, err } diff --git a/parser/hysteria2.go b/parser/hysteria2.go index 1569f7d..56c7f0f 100644 --- a/parser/hysteria2.go +++ b/parser/hysteria2.go @@ -54,7 +54,7 @@ func ParseHysteria2(proxy string) (model.Outbound, error) { } } network, obfs, obfsPassword, pinSHA256, insecure, sni := query.Get("network"), query.Get("obfs"), query.Get("obfs-password"), query.Get("pinSHA256"), query.Get("insecure"), query.Get("sni") - enableTLS := pinSHA256 != "" + enableTLS := pinSHA256 != "" || sni != "" insecureBool := insecure == "1" remarks := link.Fragment if remarks == "" { @@ -71,18 +71,24 @@ func ParseHysteria2(proxy string) (model.Outbound, error) { ServerPort: port, }, Password: password, - Obfs: &model.Hysteria2Obfs{ - Type: obfs, - Password: obfsPassword, - }, OutboundTLSOptionsContainer: model.OutboundTLSOptionsContainer{ - TLS: &model.OutboundTLSOptions{Enabled: enableTLS, - Insecure: insecureBool, - ServerName: sni, - Certificate: []string{pinSHA256}}, + TLS: &model.OutboundTLSOptions{ + Enabled: enableTLS, + Insecure: insecureBool, + ServerName: sni, + }, }, Network: network, }, } + if pinSHA256 != "" { + result.Hysteria2Options.OutboundTLSOptionsContainer.TLS.Certificate = []string{pinSHA256} + } + if obfs != "" { + result.Hysteria2Options.Obfs = &model.Hysteria2Obfs{ + Type: obfs, + Password: obfsPassword, + } + } return result, nil }