fix: 文件/配置/菜单权限接口变更

This commit is contained in:
TsMask
2025-02-26 17:55:00 +08:00
parent f337dfa683
commit 5c45a9b08e
4 changed files with 52 additions and 51 deletions

View File

@@ -89,11 +89,11 @@ func Setup(router *gin.Engine) {
// 文件操作处理
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("/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.NewFile.TransferStaticFile)
fileGroup.POST("/chunk-check", middleware.PreAuthorize(nil), controller.NewFile.ChunkCheck)
fileGroup.POST("/chunk-upload", middleware.PreAuthorize(nil), controller.NewFile.ChunkUpload)
fileGroup.POST("/chunk-merge", middleware.PreAuthorize(nil), controller.NewFile.ChunkMerge)
fileGroup.GET("/download/:filePath", middleware.PreAuthorize(nil), controller.NewFile.Download)
fileGroup.POST("/transfer-static-file", middleware.PreAuthorize(nil), controller.NewFile.TransferStaticFile)
}
}

View File

@@ -82,39 +82,41 @@ func (s *FileController) Download(c *gin.Context) {
// @Description Upload a file, interface param use <fileName>
// @Router /file/upload [post]
func (s *FileController) Upload(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
// 上传的文件
formFile, err := c.FormFile("file")
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
}
// 子路径
// 子路径需要在指定范围内
subPath := c.PostForm("subPath")
if _, ok := constants.UPLOAD_SUB_PATH[subPath]; !ok {
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
_, ok := constants.UPLOAD_SUB_PATH[subPath]
if subPath != "" && !ok {
c.JSON(400, resp.CodeMsg(40010, "bind err: subPath not in range"))
return
}
if subPath == "" {
subPath = constants.UPLOAD_COMMON
}
// 上传文件转存
upFilePath, err := file.TransferUploadFile(formFile, subPath, nil)
uploadFilePath, err := file.TransferUploadFile(formFile, subPath, []string{})
if err != nil {
c.JSON(200, resp.ErrMsg(err.Error()))
return
}
newFileName := upFilePath[strings.LastIndex(upFilePath, "/")+1:]
c.JSON(200, resp.OkData(map[string]string{
"url": "//" + c.Request.Host + upFilePath,
"fileName": upFilePath,
"newFileName": newFileName,
"url": "//" + c.Request.Host + uploadFilePath,
"filePath": uploadFilePath,
"newFileName": filepath.Base(uploadFilePath),
"originalFileName": formFile.Filename,
}))
}
// 切片文件检查
//
// POST /chunkCheck
// POST /chunk-check
//
// @Tags common/file
// @Accept json
@@ -124,18 +126,15 @@ func (s *FileController) Upload(c *gin.Context) {
// @Security TokenAuth
// @Summary Slice file checking
// @Description Slice file checking
// @Router /file/chunkCheck [post]
// @Router /file/chunk-check [post]
func (s *FileController) ChunkCheck(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body struct {
// 唯一标识
Identifier string `json:"identifier" binding:"required"`
// 文件名
FileName string `json:"fileName" binding:"required"`
Identifier string `json:"identifier" binding:"required"` // 唯一标识
FileName string `json:"fileName" binding:"required"` // 文件名
}
err := c.ShouldBindJSON(&body)
if err != nil {
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
return
}
@@ -150,7 +149,7 @@ func (s *FileController) ChunkCheck(c *gin.Context) {
// 切片文件合并
//
// POST /chunkMerge
// POST /chunk-merge
//
// @Tags common/file
// @Accept json
@@ -160,26 +159,26 @@ func (s *FileController) ChunkCheck(c *gin.Context) {
// @Security TokenAuth
// @Summary Slice file merge
// @Description Slice file merge
// @Router /file/chunkMerge [post]
// @Router /file/chunk-merge [post]
func (s *FileController) ChunkMerge(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body struct {
// 唯一标识
Identifier string `json:"identifier" binding:"required"`
// 文件名
FileName string `json:"fileName" binding:"required"`
// 子路径类型
SubPath string `json:"subPath" binding:"required"`
Identifier string `json:"identifier" binding:"required"` // 唯一标识
FileName string `json:"fileName" binding:"required"` // 文件名
SubPath string `json:"subPath"` // 子路径类型
}
err := c.ShouldBindJSON(&body)
if err != nil {
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err := c.ShouldBindJSON(&body); err != nil {
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
c.JSON(422, resp.CodeMsg(40422, errMsgs))
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
}
if body.SubPath == "" {
body.SubPath = constants.UPLOAD_COMMON
}
// 切片文件合并
mergeFilePath, err := file.ChunkMergeFile(body.Identifier, body.FileName, body.SubPath)
@@ -188,18 +187,17 @@ func (s *FileController) ChunkMerge(c *gin.Context) {
return
}
newFileName := mergeFilePath[strings.LastIndex(mergeFilePath, "/")+1:]
c.JSON(200, resp.OkData(map[string]string{
"url": "//" + c.Request.Host + mergeFilePath,
"fileName": mergeFilePath,
"newFileName": newFileName,
"filePath": mergeFilePath,
"newFileName": filepath.Base(mergeFilePath),
"originalFileName": body.FileName,
}))
}
// 切片文件上传
//
// POST /chunkUpload
// POST /chunk-upload
//
// @Tags common/file
// @Accept multipart/form-data
@@ -211,17 +209,20 @@ func (s *FileController) ChunkMerge(c *gin.Context) {
// @Security TokenAuth
// @Summary Sliced file upload
// @Description Sliced file upload
// @Router /file/chunkUpload [post]
// @Router /file/chunk-upload [post]
func (s *FileController) ChunkUpload(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
// 切片编号
index := c.PostForm("index")
// 切片唯一标识
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")
if index == "" || identifier == "" || err != nil {
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
if err != nil {
c.JSON(400, resp.CodeMsg(40010, "bind err: file is empty"))
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) {
var body struct {
UploadPath string `json:"uploadPath" binding:"required"`

View File

@@ -310,7 +310,7 @@ func (s SysConfigController) Export(c *gin.Context) {
// 参数配置修改配置参数
//
// PUT /changeValue
// PUT /change-value
func (s *SysConfigController) ConfigValue(c *gin.Context) {
language := reqctx.AcceptLanguage(c)
var body struct {

View File

@@ -62,7 +62,7 @@ func Setup(router *gin.Engine) {
controller.NewSysConfig.Export,
)
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)),
controller.NewSysConfig.ConfigValue,
)
@@ -234,7 +234,7 @@ func Setup(router *gin.Engine) {
sysMenuGroup := router.Group("/system/menu")
{
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,
)
sysMenuGroup.GET("/:menuId",