2021-11-11 15:56:02 +08:00
|
|
|
package router
|
2021-05-08 18:00:33 +08:00
|
|
|
|
|
|
|
|
import (
|
2022-06-02 17:41:11 +08:00
|
|
|
"mayfly-go/internal/devops/api"
|
|
|
|
|
"mayfly-go/internal/devops/application"
|
|
|
|
|
sysApplication "mayfly-go/internal/sys/application"
|
|
|
|
|
"mayfly-go/pkg/ctx"
|
2021-05-08 18:00:33 +08:00
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func InitMachineFileRouter(router *gin.RouterGroup) {
|
|
|
|
|
machineFile := router.Group("machines")
|
|
|
|
|
{
|
2021-09-11 14:04:09 +08:00
|
|
|
mf := &api.MachineFile{
|
2021-07-28 18:03:19 +08:00
|
|
|
MachineFileApp: application.MachineFileApp,
|
2021-12-02 10:35:48 +08:00
|
|
|
MachineApp: application.MachineApp,
|
|
|
|
|
MsgApp: sysApplication.MsgApp,
|
|
|
|
|
}
|
2021-05-08 18:00:33 +08:00
|
|
|
|
|
|
|
|
// 获取指定机器文件列表
|
|
|
|
|
machineFile.GET(":machineId/files", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).Handle(mf.MachineFiles)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 新增修改机器文件
|
2021-06-07 17:22:07 +08:00
|
|
|
addFileConf := ctx.NewLogInfo("新增机器文件配置")
|
2021-06-09 16:58:57 +08:00
|
|
|
afcP := ctx.NewPermission("machine:file:add")
|
2021-05-08 18:00:33 +08:00
|
|
|
machineFile.POST(":machineId/files", func(c *gin.Context) {
|
2021-06-09 16:58:57 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).WithLog(addFileConf).
|
|
|
|
|
WithRequiredPermission(afcP).
|
|
|
|
|
Handle(mf.SaveMachineFiles)
|
2021-05-08 18:00:33 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 删除机器文件
|
2021-06-09 16:58:57 +08:00
|
|
|
delFileConf := ctx.NewLogInfo("删除机器文件配置")
|
|
|
|
|
dfcP := ctx.NewPermission("machine:file:del")
|
2021-05-08 18:00:33 +08:00
|
|
|
machineFile.DELETE(":machineId/files/:fileId", func(c *gin.Context) {
|
2021-06-09 16:58:57 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).WithLog(delFileConf).
|
|
|
|
|
WithRequiredPermission(dfcP).
|
|
|
|
|
Handle(mf.DeleteFile)
|
2021-05-08 18:00:33 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
getContent := ctx.NewLogInfo("读取机器文件内容")
|
|
|
|
|
machineFile.GET(":machineId/files/:fileId/read", func(c *gin.Context) {
|
2022-07-04 20:21:24 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).WithLog(getContent).
|
|
|
|
|
Handle(mf.ReadFileContent)
|
2021-05-08 18:00:33 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
getDir := ctx.NewLogInfo("读取机器目录")
|
|
|
|
|
machineFile.GET(":machineId/files/:fileId/read-dir", func(c *gin.Context) {
|
2022-07-04 20:21:24 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).WithLog(getDir).
|
|
|
|
|
Handle(mf.GetDirEntry)
|
2021-05-08 18:00:33 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
writeFile := ctx.NewLogInfo("写入or下载文件内容")
|
2021-06-09 16:58:57 +08:00
|
|
|
wfP := ctx.NewPermission("machine:file:write")
|
2021-05-08 18:00:33 +08:00
|
|
|
machineFile.POST(":machineId/files/:fileId/write", func(c *gin.Context) {
|
2021-06-09 16:58:57 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).WithLog(writeFile).
|
|
|
|
|
WithRequiredPermission(wfP).
|
|
|
|
|
Handle(mf.WriteFileContent)
|
2021-05-08 18:00:33 +08:00
|
|
|
})
|
|
|
|
|
|
2022-07-04 20:21:24 +08:00
|
|
|
createFile := ctx.NewLogInfo("创建机器文件or目录")
|
|
|
|
|
machineFile.POST(":machineId/files/:fileId/create-file", func(c *gin.Context) {
|
|
|
|
|
ctx.NewReqCtxWithGin(c).WithLog(createFile).
|
|
|
|
|
WithRequiredPermission(wfP).
|
|
|
|
|
Handle(mf.CreateFile)
|
|
|
|
|
})
|
|
|
|
|
|
2021-05-08 18:00:33 +08:00
|
|
|
uploadFile := ctx.NewLogInfo("文件上传")
|
2021-06-09 16:58:57 +08:00
|
|
|
ufP := ctx.NewPermission("machine:file:upload")
|
2021-05-08 18:00:33 +08:00
|
|
|
machineFile.POST(":machineId/files/:fileId/upload", func(c *gin.Context) {
|
2021-06-09 16:58:57 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).WithLog(uploadFile).
|
|
|
|
|
WithRequiredPermission(ufP).
|
|
|
|
|
Handle(mf.UploadFile)
|
2021-05-08 18:00:33 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
removeFile := ctx.NewLogInfo("删除文件or文件夹")
|
2021-06-09 16:58:57 +08:00
|
|
|
rfP := ctx.NewPermission("machine:file:rm")
|
2021-05-08 18:00:33 +08:00
|
|
|
machineFile.DELETE(":machineId/files/:fileId/remove", func(c *gin.Context) {
|
2021-06-09 16:58:57 +08:00
|
|
|
ctx.NewReqCtxWithGin(c).WithLog(removeFile).
|
|
|
|
|
WithRequiredPermission(rfP).
|
|
|
|
|
Handle(mf.RemoveFile)
|
2021-05-08 18:00:33 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|