fix:: 请求响应码用常量

This commit is contained in:
TsMask
2025-06-07 16:32:04 +08:00
parent c67fbb7998
commit 33b95a6e30
73 changed files with 441 additions and 375 deletions

View File

@@ -146,7 +146,7 @@ func (s *BootloaderController) Account(c *gin.Context) {
}
if err := c.ShouldBindJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(422001, errMsgs))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return
}

View File

@@ -33,7 +33,7 @@ func (s CommonController) Hash(c *gin.Context) {
}
if err := c.ShouldBindJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(422001, errMsgs))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return
}

View File

@@ -34,13 +34,13 @@ func (s *FileController) Download(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
filePath := c.Param("filePath")
if len(filePath) < 8 {
c.JSON(422, resp.CodeMsg(422002, i18n.TKey(language, "app.common.err400")))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, i18n.TKey(language, "app.common.err400")))
return
}
// base64解析出地址
decodedBytes, err := base64.StdEncoding.DecodeString(filePath)
if err != nil {
c.JSON(422, resp.CodeMsg(422002, err.Error()))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, err.Error()))
return
}
routerPath := string(decodedBytes)
@@ -87,14 +87,14 @@ func (s *FileController) Upload(c *gin.Context) {
// 上传的文件
formFile, err := c.FormFile("file")
if err != nil {
c.JSON(422, resp.CodeMsg(422002, "bind err: file is empty"))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "bind err: file is empty"))
return
}
// 子路径需要在指定范围内
subPath := c.PostForm("subPath")
_, ok := constants.UPLOAD_SUB_PATH[subPath]
if subPath != "" && !ok {
c.JSON(422, resp.CodeMsg(422002, "bind err: subPath not in range"))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "bind err: subPath not in range"))
return
}
if subPath == "" {
@@ -136,7 +136,7 @@ func (s *FileController) ChunkCheck(c *gin.Context) {
}
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(422001, errMsgs))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return
}
@@ -170,12 +170,12 @@ func (s *FileController) ChunkMerge(c *gin.Context) {
}
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(422001, errMsgs))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return
}
// 子路径需要在指定范围内
if _, ok := constants.UPLOAD_SUB_PATH[body.SubPath]; body.SubPath != "" && !ok {
c.JSON(422, resp.CodeMsg(422002, "bind err: subPath not in range"))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "bind err: subPath not in range"))
return
}
if body.SubPath == "" {
@@ -218,13 +218,13 @@ func (s *FileController) ChunkUpload(c *gin.Context) {
// 切片唯一标识
identifier := c.PostForm("identifier")
if index == "" || identifier == "" {
c.JSON(422, resp.CodeMsg(422002, "bind err: index and identifier must be set"))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "bind err: index and identifier must be set"))
return
}
// 上传的文件
formFile, err := c.FormFile("file")
if err != nil {
c.JSON(422, resp.CodeMsg(422002, "bind err: file is empty"))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_CHEACK, "bind err: file is empty"))
return
}
@@ -262,7 +262,7 @@ func (s *FileController) List(c *gin.Context) {
}
if err := c.ShouldBindQuery(&querys); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(422001, errMsgs))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return
}
@@ -322,12 +322,12 @@ func (s *FileController) File(c *gin.Context) {
}
if err := c.ShouldBindQuery(&querys); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(422001, errMsgs))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return
}
// 检查路径是否在允许的目录范围内
allowedPaths := []string{"/var/log", "/tmp", "/usr/local/omc/backup"}
allowedPaths := []string{"/var/log", "/tmp", "/usr/local/omc"}
allowed := false
for _, p := range allowedPaths {
if strings.HasPrefix(querys.Path, p) {
@@ -373,7 +373,7 @@ func (s *FileController) Remove(c *gin.Context) {
}
if err := c.ShouldBindQuery(&querys); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(422001, errMsgs))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return
}
@@ -418,7 +418,7 @@ func (s *FileController) TransferStaticFile(c *gin.Context) {
}
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(422001, errMsgs))
c.JSON(422, resp.CodeMsg(resp.CODE_PARAM_PARSER, errMsgs))
return
}