add icon upload impl
This commit is contained in:
parent
bd2c1f07e7
commit
ad8590347a
|
|
@ -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]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue