feat: 通用模块多语言

This commit is contained in:
TsMask
2023-11-20 18:53:25 +08:00
parent a5139cf29c
commit 506866e082
5 changed files with 97 additions and 45 deletions

View File

@@ -7,6 +7,8 @@ import (
"strings"
"ems.agt/src/framework/constants/uploadsubpath"
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/file"
"ems.agt/src/framework/vo/result"
@@ -25,9 +27,10 @@ type FileController struct{}
//
// GET /download/:filePath
func (s *FileController) Download(c *gin.Context) {
language := ctx.AcceptLanguage(c)
filePath := c.Param("filePath")
if len(filePath) < 8 {
c.JSON(400, result.CodeMsg(400, "parameter error"))
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// base64解析出地址
@@ -68,16 +71,17 @@ func (s *FileController) Download(c *gin.Context) {
//
// POST /upload
func (s *FileController) Upload(c *gin.Context) {
language := ctx.AcceptLanguage(c)
// 上传的文件
formFile, err := c.FormFile("file")
if err != nil {
c.JSON(400, result.CodeMsg(400, "parameter error"))
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 子路径
subPath := c.PostForm("subPath")
if _, ok := uploadsubpath.UploadSubpath[subPath]; !ok {
c.JSON(400, result.CodeMsg(400, "parameter error"))
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -101,6 +105,7 @@ func (s *FileController) Upload(c *gin.Context) {
//
// POST /chunkCheck
func (s *FileController) ChunkCheck(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var body struct {
// 唯一标识
Identifier string `json:"identifier" binding:"required"`
@@ -109,7 +114,7 @@ func (s *FileController) ChunkCheck(c *gin.Context) {
}
err := c.ShouldBindJSON(&body)
if err != nil {
c.JSON(400, result.CodeMsg(400, "parameter error"))
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -126,6 +131,7 @@ func (s *FileController) ChunkCheck(c *gin.Context) {
//
// POST /chunkMerge
func (s *FileController) ChunkMerge(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var body struct {
// 唯一标识
Identifier string `json:"identifier" binding:"required"`
@@ -136,11 +142,11 @@ func (s *FileController) ChunkMerge(c *gin.Context) {
}
err := c.ShouldBindJSON(&body)
if err != nil {
c.JSON(400, result.CodeMsg(400, "parameter error"))
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
if _, ok := uploadsubpath.UploadSubpath[body.SubPath]; !ok {
c.JSON(400, result.CodeMsg(400, "parameter error"))
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -164,6 +170,7 @@ func (s *FileController) ChunkMerge(c *gin.Context) {
//
// POST /chunkUpload
func (s *FileController) ChunkUpload(c *gin.Context) {
language := ctx.AcceptLanguage(c)
// 切片编号
index := c.PostForm("index")
// 切片唯一标识
@@ -171,7 +178,7 @@ func (s *FileController) ChunkUpload(c *gin.Context) {
// 上传的文件
formFile, err := c.FormFile("file")
if index == "" || identifier == "" || err != nil {
c.JSON(400, result.CodeMsg(400, "parameter error"))
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}