Skip to content

Commit

Permalink
feat: support base64 decode before resolve clash subscription. #22
Browse files Browse the repository at this point in the history
  • Loading branch information
mzz2017 committed Sep 28, 2022
1 parent ef64eae commit 60b77f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions cmd/subscription.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"bytes"
"encoding/json"
"fmt"
"github.com/mzz2017/gg/common"
Expand Down Expand Up @@ -41,8 +40,14 @@ type SIP008Server struct {
func resolveSubscriptionAsClash(log *logrus.Logger, b []byte) (dialers []*dialer.Dialer, err error) {
log.Traceln("try to resolve as Clash")

// base64 decode
raw, e := common.Base64StdDecode(string(b))
if e != nil {
raw, _ = common.Base64URLDecode(string(b))
}

var conf ClashConfig
if err = yaml.NewDecoder(bytes.NewReader(b)).Decode(&conf); err != nil {
if err = yaml.NewDecoder(strings.NewReader(raw)).Decode(&conf); err != nil {
return nil, err
}
for i, node := range conf.Proxy {
Expand Down
4 changes: 2 additions & 2 deletions common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Base64StdDecode(s string) (string, error) {
if err != nil {
return saver, err
}
return string(raw), err
return string(raw), nil
}

func BoolToString(b bool) string {
Expand All @@ -46,7 +46,7 @@ func Base64URLDecode(s string) (string, error) {
if err != nil {
return saver, err
}
return string(raw), err
return string(raw), nil
}

func ObjectToKV(v interface{}, tagName string) (kv []string) {
Expand Down

0 comments on commit 60b77f0

Please sign in to comment.