feat: optional provider path (#624)

This commit is contained in:
汐殇
2023-06-15 22:45:02 +08:00
committed by GitHub
parent af28b99b2a
commit 77fb9a9c01
3 changed files with 39 additions and 10 deletions

View File

@ -1,6 +1,8 @@
package constant
import (
"crypto/md5"
"encoding/hex"
"os"
P "path"
"path/filepath"
@ -72,6 +74,12 @@ func (p *path) IsSafePath(path string) bool {
return !strings.Contains(rel, "..")
}
func (p *path) GetRandomPath(prefix, name string) string {
hash := md5.Sum([]byte(name))
filename := hex.EncodeToString(hash[:])
return filepath.Join(p.HomeDir(), prefix, filename)
}
func (p *path) MMDB() string {
files, err := os.ReadDir(p.homeDir)
if err != nil {