2022-11-22 07:54:18 +00:00
|
|
|
package utils
|
|
|
|
|
2022-11-30 12:46:54 +00:00
|
|
|
import (
|
2023-08-27 13:14:23 +00:00
|
|
|
"encoding/base64"
|
2022-11-30 12:46:54 +00:00
|
|
|
"strings"
|
2022-11-22 07:54:18 +00:00
|
|
|
|
2022-11-30 12:46:54 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/conf"
|
|
|
|
)
|
|
|
|
|
|
|
|
func MappingName(name string) string {
|
|
|
|
for k, v := range conf.FilenameCharMap {
|
2022-11-22 07:54:18 +00:00
|
|
|
name = strings.ReplaceAll(name, k, v)
|
|
|
|
}
|
|
|
|
return name
|
|
|
|
}
|
2023-08-27 13:14:23 +00:00
|
|
|
|
|
|
|
var DEC = map[string]string{
|
|
|
|
"-": "+",
|
|
|
|
"_": "/",
|
|
|
|
".": "=",
|
|
|
|
}
|
|
|
|
|
|
|
|
func SafeAtob(data string) (string, error) {
|
|
|
|
for k, v := range DEC {
|
|
|
|
data = strings.ReplaceAll(data, k, v)
|
|
|
|
}
|
|
|
|
bytes, err := base64.StdEncoding.DecodeString(data)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return string(bytes), err
|
|
|
|
}
|
2023-09-03 10:06:44 +00:00
|
|
|
|
|
|
|
// GetNoneEmpty returns the first non-empty string, return empty if all empty
|
|
|
|
func GetNoneEmpty(strArr ...string) string {
|
|
|
|
for _, s := range strArr {
|
|
|
|
if len(s) > 0 {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|