diff --git a/script/config.go b/script/config.go index f980a0f..f3ffe8c 100644 --- a/script/config.go +++ b/script/config.go @@ -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] +} diff --git a/service/accounts.go b/service/accounts.go index cad649c..76b8ffa 100644 --- a/service/accounts.go +++ b/service/accounts.go @@ -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 {