🆕新增了一个破逼头像生成

This commit is contained in:
coward 2024-07-11 16:12:46 +08:00
parent b51dfea18b
commit 8de68413c1
2 changed files with 17 additions and 0 deletions

View File

@ -1,7 +1,9 @@
package api
import (
"encoding/base64"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"wireguard-ui/global/constant"
"wireguard-ui/http/param"
@ -250,3 +252,17 @@ func (UserApi) ResetPassword(c *gin.Context) {
response.R(c).OK()
}
// GenerateAvatar
// @description: 生成头像
// @receiver UserApi
// @param c
func (UserApi) GenerateAvatar(c *gin.Context) {
avatar, err := utils.Avatar().GenerateAvatar(false)
if err != nil {
response.R(c).FailedWithError(fmt.Errorf("生成头像失败: %s", err.Error()))
return
}
response.R(c).OkWithData(fmt.Sprintf("data:image/png;base64,%s", base64.StdEncoding.EncodeToString([]byte(avatar))))
}

View File

@ -19,5 +19,6 @@ func UserApi(r *gin.RouterGroup) {
userApi.PUT("/status/:id", api.User().Status) // 修改用户状态
userApi.PUT("/change-password", api.User().ChangePassword) // 修改用户密码
userApi.PUT("/reset-password/:id", api.User().ResetPassword) // 重置用户密码
userApi.POST("/generate-avatar", api.User().GenerateAvatar) // 生成头像
}
}