Compare commits

...

2 Commits

Author SHA1 Message Date
junleea f7b1c935f4 文件更新 2024-08-30 22:54:13 +08:00
junleea 2034cfd784 文件查看功能 2024-08-30 22:42:18 +08:00
2 changed files with 59 additions and 0 deletions

View File

@ -53,6 +53,22 @@ func UpdateFileByID(id, auth_id int, fileStoreName, fileName, fileType, filePath
if pd.ID == 0 {
return false
}
if fileStoreName == "" {
fileStoreName = pd.FileStoreName
}
if fileName == "" {
fileName = pd.FileName
}
if fileType == "" {
fileType = pd.FileType
}
if filePath == "" {
filePath = pd.FilePath
}
if fileSize == 0 {
fileSize = pd.FileSize
}
result := DB.Debug().Model(&File{}).Where("id = ? and auth_id = ?", id, auth_id).Updates(File{FileStoreName: fileStoreName, FileName: fileName, FileType: fileType, FilePath: filePath, FileSize: fileSize})
if result.Error != nil {
return false

View File

@ -10,6 +10,7 @@ import (
"videoplayer/dao"
"videoplayer/proto"
"videoplayer/service"
"videoplayer/worker"
)
type SetRedisReq struct {
@ -19,6 +20,14 @@ type SetRedisReq struct {
Expire int `json:"expire" form:"expire"`
}
type SetFileReq struct {
ID int `json:"id" form:"id"`
FileStoreName string `json:"file_store_name" form:"file_store_name"`
FileName string `json:"file_name" form:"file_name"`
FileSize int `json:"file_size" form:"file_size"`
FileType string `json:"file_type" form:"file_type"`
}
func SetUpToolGroup(router *gin.Engine) {
toolGroup := router.Group("/tool")
toolGroup.POST("/set_redis", SetRedis)
@ -29,6 +38,40 @@ func SetUpToolGroup(router *gin.Engine) {
toolGroup.GET("/download", DownloadFile)
//文件管理
toolGroup.POST("/file_del", DelFile)
toolGroup.POST("/file_status", FileStatus)
toolGroup.POST("/file_set", SetFile)
}
func SetFile(c *gin.Context) {
id, _ := c.Get("id")
id1 := int(id.(float64))
var req SetFileReq
if err := c.ShouldBind(&req); err == nil {
//先查看是否有权限
dao.UpdateFileByID(req.ID, id1, req.FileStoreName, req.FileName, req.FileType, "", req.FileSize)
} else {
c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"})
}
}
func FileStatus(c *gin.Context) {
//先查看是否有权限
id, _ := c.Get("id")
id1 := int(id.(float64))
file_id, _ := strconv.Atoi(c.PostForm("id"))
file_ := dao.FindFileByID(file_id, id1)
if file_.ID == 0 {
c.JSON(http.StatusOK, gin.H{"error": "file not found", "code": proto.FileNotFound, "message": "failed"})
return
}
res := worker.GetRedis(file_.FileStoreName)
//查看文件信息
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": file_, "status": res})
}
func DelFile(c *gin.Context) {