upload_file.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package task
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "go.uber.org/zap"
  6. "log-server/global"
  7. "log-server/model/common/response"
  8. taskRes "log-server/model/task/response"
  9. "strconv"
  10. )
  11. type UploadFileApi struct {
  12. }
  13. func (b *UploadFileApi) UploadFile(c *gin.Context) {
  14. _, header, err := c.Request.FormFile("file")
  15. if err != nil {
  16. global.GVA_LOG.Error("接收文件失败!", zap.Error(err))
  17. response.FailWithMessage("接收文件失败", c)
  18. return
  19. }
  20. gameID := c.PostForm("game_id")
  21. var fileRes taskRes.UploadFileResponse
  22. gameId, _ := strconv.Atoi(gameID)
  23. fileRes, err = uploadFileService.UploadFile(gameId, header) // 文件上传后拿到文件路径
  24. if err != nil {
  25. global.GVA_LOG.Error("修改数据库链接失败!", zap.Error(err))
  26. response.FailWithMessage("修改数据库链接失败", c)
  27. return
  28. }
  29. response.OkWithDetailed(taskRes.InfoResponse{fileRes}, "上传成功", c)
  30. }
  31. func (b *UploadFileApi) DownloadFile(c *gin.Context) {
  32. gameIdStr := c.Query("gameId")
  33. md5String := c.Query("md5String")
  34. fmt.Println(gameIdStr)
  35. gameId, _ := strconv.Atoi(gameIdStr)
  36. downloadFile, err := uploadFileService.DownloadFile(gameId, md5String)
  37. if err != nil {
  38. global.GVA_LOG.Error("查询失败!", zap.Error(err))
  39. response.FailWithMessage("查询失败", c)
  40. } else {
  41. response.OkWithDetailed(taskRes.DownloadInfoResponse{downloadFile}, "查询成功", c)
  42. }
  43. }