fix: 文件/配置/菜单权限接口变更
This commit is contained in:
@@ -89,11 +89,11 @@ func Setup(router *gin.Engine) {
|
|||||||
// 文件操作处理
|
// 文件操作处理
|
||||||
fileGroup := router.Group("/file")
|
fileGroup := router.Group("/file")
|
||||||
{
|
{
|
||||||
fileGroup.GET("/download/:filePath", middleware.PreAuthorize(nil), controller.NewFile.Download)
|
|
||||||
fileGroup.POST("/upload", middleware.PreAuthorize(nil), controller.NewFile.Upload)
|
fileGroup.POST("/upload", middleware.PreAuthorize(nil), controller.NewFile.Upload)
|
||||||
fileGroup.POST("/chunkCheck", middleware.PreAuthorize(nil), controller.NewFile.ChunkCheck)
|
fileGroup.POST("/chunk-check", middleware.PreAuthorize(nil), controller.NewFile.ChunkCheck)
|
||||||
fileGroup.POST("/chunkUpload", middleware.PreAuthorize(nil), controller.NewFile.ChunkUpload)
|
fileGroup.POST("/chunk-upload", middleware.PreAuthorize(nil), controller.NewFile.ChunkUpload)
|
||||||
fileGroup.POST("/chunkMerge", middleware.PreAuthorize(nil), controller.NewFile.ChunkMerge)
|
fileGroup.POST("/chunk-merge", middleware.PreAuthorize(nil), controller.NewFile.ChunkMerge)
|
||||||
fileGroup.POST("/transferStaticFile", middleware.PreAuthorize(nil), controller.NewFile.TransferStaticFile)
|
fileGroup.GET("/download/:filePath", middleware.PreAuthorize(nil), controller.NewFile.Download)
|
||||||
|
fileGroup.POST("/transfer-static-file", middleware.PreAuthorize(nil), controller.NewFile.TransferStaticFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,39 +82,41 @@ func (s *FileController) Download(c *gin.Context) {
|
|||||||
// @Description Upload a file, interface param use <fileName>
|
// @Description Upload a file, interface param use <fileName>
|
||||||
// @Router /file/upload [post]
|
// @Router /file/upload [post]
|
||||||
func (s *FileController) Upload(c *gin.Context) {
|
func (s *FileController) Upload(c *gin.Context) {
|
||||||
language := reqctx.AcceptLanguage(c)
|
|
||||||
// 上传的文件
|
// 上传的文件
|
||||||
formFile, err := c.FormFile("file")
|
formFile, err := c.FormFile("file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
c.JSON(400, resp.CodeMsg(40010, "bind err: file is empty"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 子路径
|
// 子路径需要在指定范围内
|
||||||
subPath := c.PostForm("subPath")
|
subPath := c.PostForm("subPath")
|
||||||
if _, ok := constants.UPLOAD_SUB_PATH[subPath]; !ok {
|
_, ok := constants.UPLOAD_SUB_PATH[subPath]
|
||||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
if subPath != "" && !ok {
|
||||||
|
c.JSON(400, resp.CodeMsg(40010, "bind err: subPath not in range"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if subPath == "" {
|
||||||
|
subPath = constants.UPLOAD_COMMON
|
||||||
|
}
|
||||||
|
|
||||||
// 上传文件转存
|
// 上传文件转存
|
||||||
upFilePath, err := file.TransferUploadFile(formFile, subPath, nil)
|
uploadFilePath, err := file.TransferUploadFile(formFile, subPath, []string{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
newFileName := upFilePath[strings.LastIndex(upFilePath, "/")+1:]
|
|
||||||
c.JSON(200, resp.OkData(map[string]string{
|
c.JSON(200, resp.OkData(map[string]string{
|
||||||
"url": "//" + c.Request.Host + upFilePath,
|
"url": "//" + c.Request.Host + uploadFilePath,
|
||||||
"fileName": upFilePath,
|
"filePath": uploadFilePath,
|
||||||
"newFileName": newFileName,
|
"newFileName": filepath.Base(uploadFilePath),
|
||||||
"originalFileName": formFile.Filename,
|
"originalFileName": formFile.Filename,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 切片文件检查
|
// 切片文件检查
|
||||||
//
|
//
|
||||||
// POST /chunkCheck
|
// POST /chunk-check
|
||||||
//
|
//
|
||||||
// @Tags common/file
|
// @Tags common/file
|
||||||
// @Accept json
|
// @Accept json
|
||||||
@@ -124,18 +126,15 @@ func (s *FileController) Upload(c *gin.Context) {
|
|||||||
// @Security TokenAuth
|
// @Security TokenAuth
|
||||||
// @Summary Slice file checking
|
// @Summary Slice file checking
|
||||||
// @Description Slice file checking
|
// @Description Slice file checking
|
||||||
// @Router /file/chunkCheck [post]
|
// @Router /file/chunk-check [post]
|
||||||
func (s *FileController) ChunkCheck(c *gin.Context) {
|
func (s *FileController) ChunkCheck(c *gin.Context) {
|
||||||
language := reqctx.AcceptLanguage(c)
|
|
||||||
var body struct {
|
var body struct {
|
||||||
// 唯一标识
|
Identifier string `json:"identifier" binding:"required"` // 唯一标识
|
||||||
Identifier string `json:"identifier" binding:"required"`
|
FileName string `json:"fileName" binding:"required"` // 文件名
|
||||||
// 文件名
|
|
||||||
FileName string `json:"fileName" binding:"required"`
|
|
||||||
}
|
}
|
||||||
err := c.ShouldBindJSON(&body)
|
if err := c.ShouldBindJSON(&body); err != nil {
|
||||||
if err != nil {
|
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +149,7 @@ func (s *FileController) ChunkCheck(c *gin.Context) {
|
|||||||
|
|
||||||
// 切片文件合并
|
// 切片文件合并
|
||||||
//
|
//
|
||||||
// POST /chunkMerge
|
// POST /chunk-merge
|
||||||
//
|
//
|
||||||
// @Tags common/file
|
// @Tags common/file
|
||||||
// @Accept json
|
// @Accept json
|
||||||
@@ -160,26 +159,26 @@ func (s *FileController) ChunkCheck(c *gin.Context) {
|
|||||||
// @Security TokenAuth
|
// @Security TokenAuth
|
||||||
// @Summary Slice file merge
|
// @Summary Slice file merge
|
||||||
// @Description Slice file merge
|
// @Description Slice file merge
|
||||||
// @Router /file/chunkMerge [post]
|
// @Router /file/chunk-merge [post]
|
||||||
func (s *FileController) ChunkMerge(c *gin.Context) {
|
func (s *FileController) ChunkMerge(c *gin.Context) {
|
||||||
language := reqctx.AcceptLanguage(c)
|
|
||||||
var body struct {
|
var body struct {
|
||||||
// 唯一标识
|
Identifier string `json:"identifier" binding:"required"` // 唯一标识
|
||||||
Identifier string `json:"identifier" binding:"required"`
|
FileName string `json:"fileName" binding:"required"` // 文件名
|
||||||
// 文件名
|
SubPath string `json:"subPath"` // 子路径类型
|
||||||
FileName string `json:"fileName" binding:"required"`
|
|
||||||
// 子路径类型
|
|
||||||
SubPath string `json:"subPath" binding:"required"`
|
|
||||||
}
|
}
|
||||||
err := c.ShouldBindJSON(&body)
|
if err := c.ShouldBindJSON(&body); err != nil {
|
||||||
if err != nil {
|
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, ok := constants.UPLOAD_SUB_PATH[body.SubPath]; !ok {
|
// 子路径需要在指定范围内
|
||||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
if _, ok := constants.UPLOAD_SUB_PATH[body.SubPath]; body.SubPath != "" && !ok {
|
||||||
|
c.JSON(400, resp.CodeMsg(40010, "bind err: subPath not in range"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if body.SubPath == "" {
|
||||||
|
body.SubPath = constants.UPLOAD_COMMON
|
||||||
|
}
|
||||||
|
|
||||||
// 切片文件合并
|
// 切片文件合并
|
||||||
mergeFilePath, err := file.ChunkMergeFile(body.Identifier, body.FileName, body.SubPath)
|
mergeFilePath, err := file.ChunkMergeFile(body.Identifier, body.FileName, body.SubPath)
|
||||||
@@ -188,18 +187,17 @@ func (s *FileController) ChunkMerge(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
newFileName := mergeFilePath[strings.LastIndex(mergeFilePath, "/")+1:]
|
|
||||||
c.JSON(200, resp.OkData(map[string]string{
|
c.JSON(200, resp.OkData(map[string]string{
|
||||||
"url": "//" + c.Request.Host + mergeFilePath,
|
"url": "//" + c.Request.Host + mergeFilePath,
|
||||||
"fileName": mergeFilePath,
|
"filePath": mergeFilePath,
|
||||||
"newFileName": newFileName,
|
"newFileName": filepath.Base(mergeFilePath),
|
||||||
"originalFileName": body.FileName,
|
"originalFileName": body.FileName,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 切片文件上传
|
// 切片文件上传
|
||||||
//
|
//
|
||||||
// POST /chunkUpload
|
// POST /chunk-upload
|
||||||
//
|
//
|
||||||
// @Tags common/file
|
// @Tags common/file
|
||||||
// @Accept multipart/form-data
|
// @Accept multipart/form-data
|
||||||
@@ -211,17 +209,20 @@ func (s *FileController) ChunkMerge(c *gin.Context) {
|
|||||||
// @Security TokenAuth
|
// @Security TokenAuth
|
||||||
// @Summary Sliced file upload
|
// @Summary Sliced file upload
|
||||||
// @Description Sliced file upload
|
// @Description Sliced file upload
|
||||||
// @Router /file/chunkUpload [post]
|
// @Router /file/chunk-upload [post]
|
||||||
func (s *FileController) ChunkUpload(c *gin.Context) {
|
func (s *FileController) ChunkUpload(c *gin.Context) {
|
||||||
language := reqctx.AcceptLanguage(c)
|
|
||||||
// 切片编号
|
// 切片编号
|
||||||
index := c.PostForm("index")
|
index := c.PostForm("index")
|
||||||
// 切片唯一标识
|
// 切片唯一标识
|
||||||
identifier := c.PostForm("identifier")
|
identifier := c.PostForm("identifier")
|
||||||
|
if index == "" || identifier == "" {
|
||||||
|
c.JSON(400, resp.CodeMsg(40010, "bind err: index and identifier must be set"))
|
||||||
|
return
|
||||||
|
}
|
||||||
// 上传的文件
|
// 上传的文件
|
||||||
formFile, err := c.FormFile("file")
|
formFile, err := c.FormFile("file")
|
||||||
if index == "" || identifier == "" || err != nil {
|
if err != nil {
|
||||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
c.JSON(400, resp.CodeMsg(40010, "bind err: file is empty"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,7 +237,7 @@ func (s *FileController) ChunkUpload(c *gin.Context) {
|
|||||||
|
|
||||||
// 转存指定对应文件到静态目录
|
// 转存指定对应文件到静态目录
|
||||||
//
|
//
|
||||||
// POST /transferStaticFile
|
// POST /transfer-static-file
|
||||||
func (s *FileController) TransferStaticFile(c *gin.Context) {
|
func (s *FileController) TransferStaticFile(c *gin.Context) {
|
||||||
var body struct {
|
var body struct {
|
||||||
UploadPath string `json:"uploadPath" binding:"required"`
|
UploadPath string `json:"uploadPath" binding:"required"`
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ func (s SysConfigController) Export(c *gin.Context) {
|
|||||||
|
|
||||||
// 参数配置修改配置参数
|
// 参数配置修改配置参数
|
||||||
//
|
//
|
||||||
// PUT /changeValue
|
// PUT /change-value
|
||||||
func (s *SysConfigController) ConfigValue(c *gin.Context) {
|
func (s *SysConfigController) ConfigValue(c *gin.Context) {
|
||||||
language := reqctx.AcceptLanguage(c)
|
language := reqctx.AcceptLanguage(c)
|
||||||
var body struct {
|
var body struct {
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ func Setup(router *gin.Engine) {
|
|||||||
controller.NewSysConfig.Export,
|
controller.NewSysConfig.Export,
|
||||||
)
|
)
|
||||||
sysConfigGroup.PUT("/change-value",
|
sysConfigGroup.PUT("/change-value",
|
||||||
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:config:edit"}}),
|
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:config:edit"}, "hasRoles": {"admin"}}),
|
||||||
middleware.OperateLog(middleware.OptionNew("log.operate.title.sysConfig", middleware.BUSINESS_TYPE_UPDATE)),
|
middleware.OperateLog(middleware.OptionNew("log.operate.title.sysConfig", middleware.BUSINESS_TYPE_UPDATE)),
|
||||||
controller.NewSysConfig.ConfigValue,
|
controller.NewSysConfig.ConfigValue,
|
||||||
)
|
)
|
||||||
@@ -234,7 +234,7 @@ func Setup(router *gin.Engine) {
|
|||||||
sysMenuGroup := router.Group("/system/menu")
|
sysMenuGroup := router.Group("/system/menu")
|
||||||
{
|
{
|
||||||
sysMenuGroup.GET("/list",
|
sysMenuGroup.GET("/list",
|
||||||
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:menu:list"}}),
|
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:menu:list"}, "hasRoles": {"admin"}}),
|
||||||
controller.NewSysMenu.List,
|
controller.NewSysMenu.List,
|
||||||
)
|
)
|
||||||
sysMenuGroup.GET("/:menuId",
|
sysMenuGroup.GET("/:menuId",
|
||||||
|
|||||||
Reference in New Issue
Block a user