| | |
| | | |
| | | // ---------- 游戏管理 ---------- |
| | | |
| | | // isPlainNumber 校验非空纯数字(支持小数,如 232.6) |
| | | func isPlainNumber(s string) bool { |
| | | if s == "" { |
| | | return false |
| | | } |
| | | for _, r := range s { |
| | | if (r < '0' || r > '9') && r != '.' { |
| | | return false |
| | | } |
| | | } |
| | | return true |
| | | } |
| | | |
| | | func AdminListGames(c *gin.Context) { |
| | | var games []models.Game |
| | | config.DB.Order("id DESC").Find(&games) |
| | |
| | | c.JSON(http.StatusOK, gin.H{"code": 1, "msg": "请填写游戏名称"}) |
| | | return |
| | | } |
| | | // 游戏大小/磁盘占用统一为GB,只允许纯数字(如 232.6) |
| | | if !isPlainNumber(game.Size) { |
| | | c.JSON(http.StatusOK, gin.H{"code": 1, "msg": "游戏大小请填写纯数字(单位GB),如 232.6"}) |
| | | return |
| | | } |
| | | if !isPlainNumber(game.InstallSize) { |
| | | c.JSON(http.StatusOK, gin.H{"code": 1, "msg": "磁盘占用请填写纯数字(单位GB),如 411.6"}) |
| | | return |
| | | } |
| | | if game.Screenshots == "" { |
| | | game.Screenshots = "[]" |
| | | } |