add icon upload impl

This commit is contained in:
BaoXuebin 2021-11-29 22:42:49 +08:00
parent bd2c1f07e7
commit ad8590347a
2 changed files with 28 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"os"
"regexp"
"sort"
"strings"
)
@ -294,3 +295,15 @@ func GetAccountPrefix(account string) string {
nodes := strings.Split(account, ":")
return nodes[0]
}
func GetAccountIconName(account string) string {
nodes := strings.Split(account, ":")
for i := len(nodes) - 1; i > 0; i-- {
reg := regexp.MustCompile(`^[a-zA-Z]`)
result := reg.FindAllStringSubmatch(nodes[i], -1)
if result != nil {
return nodes[i]
}
}
return nodes[0]
}

View File

@ -188,7 +188,21 @@ func CloseAccount(c *gin.Context) {
}
func ChangeAccountIcon(c *gin.Context) {
account := c.Query("account")
if account == "" {
BadRequest(c, "account is not blank")
return
}
file, _ := c.FormFile("file")
filePath := "./public/icons/" + script.GetAccountIconName(account) + ".png"
if err := c.SaveUploadedFile(file, filePath); err != nil {
InternalError(c, err.Error())
//自己完成信息提示
return
}
var result = make(map[string]string)
result["filename"] = filePath
OK(c, result)
}
type BalanceAccountForm struct {