From c943ced9f6036bd42599fc3a77496294a51a5460 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Fri, 30 Aug 2024 15:26:39 +0800 Subject: [PATCH] upload type --- handler/tool.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/handler/tool.go b/handler/tool.go index c98bc2f..86ad218 100644 --- a/handler/tool.go +++ b/handler/tool.go @@ -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