diff --git a/src/modules/common/common.go b/src/modules/common/common.go index 6890f58e..419a7ece 100644 --- a/src/modules/common/common.go +++ b/src/modules/common/common.go @@ -3,7 +3,6 @@ package common import ( "ems.agt/src/framework/logger" "ems.agt/src/framework/middleware" - "ems.agt/src/framework/middleware/collectlogs" "ems.agt/src/modules/common/controller" "github.com/gin-gonic/gin" @@ -26,12 +25,6 @@ func Setup(router *gin.Engine) { // 系统可暴露的配置信息 indexGroup.GET("/sys-conf", controller.NewCommont.SysConfig) - // 转存上传文件到静态资源 - indexGroup.POST("/transferStaticFile", - middleware.PreAuthorize(nil), - collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.helpDoc", collectlogs.BUSINESS_TYPE_UPDATE)), - controller.NewCommont.TransferStaticFile, - ) // 验证码操作处理 indexGroup.GET("/captchaImage", @@ -92,5 +85,6 @@ func Setup(router *gin.Engine) { fileGroup.POST("/chunkCheck", middleware.PreAuthorize(nil), controller.NewFile.ChunkCheck) fileGroup.POST("/chunkUpload", middleware.PreAuthorize(nil), controller.NewFile.ChunkUpload) fileGroup.POST("/chunkMerge", middleware.PreAuthorize(nil), controller.NewFile.ChunkMerge) + fileGroup.POST("/transferStaticFile", middleware.PreAuthorize(nil), controller.NewCommont.TransferStaticFile) } } diff --git a/src/modules/common/controller/common.go b/src/modules/common/controller/common.go index a47d295d..4ba37768 100644 --- a/src/modules/common/controller/common.go +++ b/src/modules/common/controller/common.go @@ -1,18 +1,11 @@ package controller import ( - "fmt" - "path/filepath" - "strings" - - "ems.agt/src/framework/config" "ems.agt/src/framework/i18n" "ems.agt/src/framework/utils/ctx" - "ems.agt/src/framework/utils/file" "ems.agt/src/framework/vo/result" commonService "ems.agt/src/modules/common/service" "github.com/gin-gonic/gin" - "github.com/gin-gonic/gin/binding" ) // 实例化控制层 CommontController 结构体 @@ -76,43 +69,3 @@ func (s *CommontController) SysConfig(c *gin.Context) { c.JSON(200, result.OkData(data)) } - -// 转存指定对应文件 -// -// POST /transferStaticFile -func (s *CommontController) TransferStaticFile(c *gin.Context) { - language := ctx.AcceptLanguage(c) - var body struct { - UploadPath string `json:"uploadPath" binding:"required"` - StaticPath string `json:"staticPath" binding:"required"` - Language string `json:"language" binding:"required"` - } - if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil { - c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) - return - } - - // 取语言前缀 - lang := strings.SplitN(body.Language, "_", 2)[0] - - // 默认静态资源 - static := config.Get("staticFile.default").(map[string]any) - dir, err := filepath.Abs(static["dir"].(string)) - if err != nil { - c.JSON(400, result.CodeMsg(400, err.Error())) - return - } - - delPrefix := strings.Replace(body.StaticPath, static["prefix"].(string), "", 1) - staticPath := strings.Replace(delPrefix, "{language}", lang, 1) - newFile := fmt.Sprintf("%s%s", dir, staticPath) - - err = file.CopyUploadFile(body.UploadPath, newFile) - if err != nil { - c.JSON(400, result.CodeMsg(400, err.Error())) - return - } - - urlPath := strings.Replace(newFile, dir, static["prefix"].(string), 1) - c.JSON(200, result.OkData(filepath.ToSlash(urlPath))) -} diff --git a/src/modules/common/controller/file.go b/src/modules/common/controller/file.go index 352fee79..d9252213 100644 --- a/src/modules/common/controller/file.go +++ b/src/modules/common/controller/file.go @@ -4,8 +4,10 @@ import ( "encoding/base64" "fmt" "net/url" + "path/filepath" "strings" + "ems.agt/src/framework/config" "ems.agt/src/framework/constants/uploadsubpath" "ems.agt/src/framework/i18n" "ems.agt/src/framework/utils/ctx" @@ -13,6 +15,7 @@ import ( "ems.agt/src/framework/vo/result" "github.com/gin-gonic/gin" + "github.com/gin-gonic/gin/binding" ) // 实例化控制层 FileController 结构体 @@ -190,3 +193,43 @@ func (s *FileController) ChunkUpload(c *gin.Context) { } c.JSON(206, result.OkData(chunkFilePath)) } + +// 转存指定对应文件到静态目录 +// +// POST /transferStaticFile +func (s *CommontController) TransferStaticFile(c *gin.Context) { + language := ctx.AcceptLanguage(c) + var body struct { + UploadPath string `json:"uploadPath" binding:"required"` + StaticPath string `json:"staticPath" binding:"required"` + Language string `json:"language" binding:"required"` + } + if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil { + c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400"))) + return + } + + // 取语言前缀 + lang := strings.SplitN(body.Language, "_", 2)[0] + + // 默认静态资源 + static := config.Get("staticFile.default").(map[string]any) + dir, err := filepath.Abs(static["dir"].(string)) + if err != nil { + c.JSON(400, result.CodeMsg(400, err.Error())) + return + } + + delPrefix := strings.Replace(body.StaticPath, static["prefix"].(string), "", 1) + staticPath := strings.Replace(delPrefix, "{language}", lang, 1) + newFile := fmt.Sprintf("%s%s", dir, staticPath) + + err = file.CopyUploadFile(body.UploadPath, newFile) + if err != nil { + c.JSON(400, result.CodeMsg(400, err.Error())) + return + } + + urlPath := strings.Replace(newFile, dir, static["prefix"].(string), 1) + c.JSON(200, result.OkData(filepath.ToSlash(urlPath))) +}