2024-03-06 16:24:49 +08:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-03-07 15:11:29 +08:00
|
|
|
"gitee.ltd/lxh/logger/log"
|
2024-03-06 16:24:49 +08:00
|
|
|
"math/rand"
|
|
|
|
"time"
|
|
|
|
"wireguard-dashboard/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
type avatar struct{}
|
|
|
|
|
|
|
|
func Avatar() avatar {
|
|
|
|
return avatar{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (avatar) GenerateAvatar() (path string, err error) {
|
|
|
|
rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
|
r := client.HttpClient.R()
|
|
|
|
result, err := r.Get(fmt.Sprintf("https://api.dicebear.com/7.x/croodles/png?seed=%d&scale=100&size=80&clip=true&randomizeIds=true&beard=variant01,variant02,variant03&"+
|
|
|
|
"eyes=variant01,variant02,variant03,variant04,variant05,variant06,variant07,variant08,variant09,variant10,variant11,variant12&mustache=variant01,variant02,variant03&"+
|
|
|
|
"topColor=000000,0fa958,699bf7", rand.Uint32()))
|
|
|
|
if err != nil {
|
2024-03-07 15:11:29 +08:00
|
|
|
log.Errorf("请求头像API失败: %v", err.Error())
|
2024-03-06 16:24:49 +08:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
filePath, err := FileSystem().UploadFile(result.Body(), ".png")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return filePath, nil
|
|
|
|
}
|