mirror of
https://github.com/bestnite/sub2clash.git
synced 2025-10-26 09:11:01 +00:00
Refactor subscription handling by removing SubConfig model, updating BuildSub function to use ConvertConfig, and enhancing Base64 decoding across parsers. Update routes and frontend to support new configuration format.
This commit is contained in:
31
utils/base64.go
Normal file
31
utils/base64.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func DecodeBase64(s string, urlSafe bool) (string, error) {
|
||||
s = strings.TrimSpace(s)
|
||||
if len(s)%4 != 0 {
|
||||
s += strings.Repeat("=", 4-len(s)%4)
|
||||
}
|
||||
var decodeStr []byte
|
||||
var err error
|
||||
if urlSafe {
|
||||
decodeStr, err = base64.URLEncoding.DecodeString(s)
|
||||
} else {
|
||||
decodeStr, err = base64.StdEncoding.DecodeString(s)
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(decodeStr), nil
|
||||
}
|
||||
|
||||
func EncodeBase64(s string, urlSafe bool) string {
|
||||
if urlSafe {
|
||||
return base64.URLEncoding.EncodeToString([]byte(s))
|
||||
}
|
||||
return base64.StdEncoding.EncodeToString([]byte(s))
|
||||
}
|
||||
Reference in New Issue
Block a user