Kaynağa Gözat

判断兑换码名称长度,改为按字符长度计算

Raymond 6 ay önce
ebeveyn
işleme
df647e7b42
1 değiştirilmiş dosya ile 2 ekleme ve 1 silme
  1. 2 1
      controller/redemption.go

+ 2 - 1
controller/redemption.go

@@ -6,6 +6,7 @@ import (
 	"one-api/common"
 	"one-api/model"
 	"strconv"
+	"unicode/utf8"
 
 	"github.com/gin-gonic/gin"
 )
@@ -63,7 +64,7 @@ func AddRedemption(c *gin.Context) {
 		common.ApiError(c, err)
 		return
 	}
-	if len(redemption.Name) == 0 || len(redemption.Name) > 20 {
+	if utf8.RuneCountInString(redemption.Name) == 0 || utf8.RuneCountInString(redemption.Name) > 20 {
 		c.JSON(http.StatusOK, gin.H{
 			"success": false,
 			"message": "兑换码名称长度必须在1-20之间",