Merge branch 'refs/heads/feat-file' into master-pg
This commit is contained in:
commit
45fa575f19
|
|
@ -3,6 +3,7 @@ package handler
|
|||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"videoplayer/dao"
|
||||
"videoplayer/proto"
|
||||
"videoplayer/service"
|
||||
|
|
@ -22,7 +23,7 @@ func SetUpToolGroup(router *gin.Engine) {
|
|||
|
||||
//文件上传、下载
|
||||
toolGroup.POST("/upload", UploadFile)
|
||||
toolGroup.GET("/download/:filename", DownloadFile)
|
||||
toolGroup.GET("/download", DownloadFile)
|
||||
}
|
||||
|
||||
func UploadFile(c *gin.Context) {
|
||||
|
|
@ -63,16 +64,18 @@ func UploadFile(c *gin.Context) {
|
|||
c.JSON(http.StatusOK, gin.H{"error": "save file info failed", "code": proto.SaveFileInfoFailed, "message": "failed"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success"})
|
||||
|
||||
}
|
||||
|
||||
func DownloadFile(c *gin.Context) {
|
||||
//参数
|
||||
filename := c.Param("filename")
|
||||
//file_id, _ := strconv.Atoi(c.Query("id"))
|
||||
//filename := c.Param("filename")
|
||||
file_id, _ := strconv.Atoi(c.Query("id"))
|
||||
id, _ := c.Get("id")
|
||||
//查询文件信息
|
||||
file := dao.FindFileByNames(filename, int(id.(float64)))
|
||||
//file := dao.FindFileByNames(file_id, int(id.(float64)))
|
||||
file := dao.FindFileByID(file_id, int(id.(float64)))
|
||||
if file.ID == 0 {
|
||||
c.JSON(http.StatusOK, gin.H{"error": "file not found", "code": proto.FileNotFound, "message": "failed"})
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in New Issue