package task import ( "fmt" "github.com/gin-gonic/gin" "go.uber.org/zap" "log-server/global" "log-server/model/common/response" taskRes "log-server/model/task/response" "strconv" ) type UploadFileApi struct { } func (b *UploadFileApi) UploadFile(c *gin.Context) { _, header, err := c.Request.FormFile("file") if err != nil { global.GVA_LOG.Error("接收文件失败!", zap.Error(err)) response.FailWithMessage("接收文件失败", c) return } gameID := c.PostForm("game_id") var fileRes taskRes.UploadFileResponse gameId, _ := strconv.Atoi(gameID) fileRes, err = uploadFileService.UploadFile(gameId, header) // 文件上传后拿到文件路径 if err != nil { global.GVA_LOG.Error("修改数据库链接失败!", zap.Error(err)) response.FailWithMessage("修改数据库链接失败", c) return } response.OkWithDetailed(taskRes.InfoResponse{fileRes}, "上传成功", c) } func (b *UploadFileApi) DownloadFile(c *gin.Context) { gameIdStr := c.Query("gameId") md5String := c.Query("md5String") fmt.Println(gameIdStr) gameId, _ := strconv.Atoi(gameIdStr) downloadFile, err := uploadFileService.DownloadFile(gameId, md5String) if err != nil { global.GVA_LOG.Error("查询失败!", zap.Error(err)) response.FailWithMessage("查询失败", c) } else { response.OkWithDetailed(taskRes.DownloadInfoResponse{downloadFile}, "查询成功", c) } }