package.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package http
  2. import (
  3. "fmt"
  4. "go-common/app/admin/main/macross/conf"
  5. "go-common/app/admin/main/macross/model/package"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. "path/filepath"
  10. "strings"
  11. )
  12. func packageUpload(c *bm.Context) {
  13. var err = c.Request.ParseMultipartForm(1 << 30)
  14. res := map[string]interface{}{}
  15. res["message"] = "success"
  16. if err != nil {
  17. log.Error("c.Request.ParseMultipartForm() error(%v)", err)
  18. res["message"] = fmt.Sprintf("%v", err)
  19. c.JSONMap(res, err)
  20. return
  21. }
  22. file, header, err := c.Request.FormFile("file")
  23. if err != nil {
  24. log.Error("c.Request.FormFile() error(%v)", err)
  25. res["message"] = fmt.Sprintf("%v", err)
  26. c.JSONMap(res, err)
  27. return
  28. }
  29. defer file.Close()
  30. var (
  31. clientType = strings.ToLower(c.Request.FormValue("client_type"))
  32. appName = c.Request.FormValue("app_name")
  33. pipelineID = c.Request.FormValue("pipeline_id")
  34. apkName = c.Request.FormValue("apk_name")
  35. channel = c.Request.FormValue("channel")
  36. saveDir = filepath.Join(clientType, appName, pipelineID)
  37. pkgInfo upload.PkgInfo
  38. )
  39. if clientType == "" || appName == "" || pipelineID == "" {
  40. errMsg := "client_type, app_name, pipeline_id can not be null"
  41. log.Error(errMsg)
  42. res["message"] = errMsg
  43. c.JSONMap(res, ecode.RequestErr)
  44. return
  45. }
  46. if clientType != "ios" && clientType != "android" {
  47. errMsg := "client_type must be 'ios' or 'android'"
  48. log.Error(errMsg)
  49. res["message"] = errMsg
  50. c.JSONMap(res, ecode.RequestErr)
  51. return
  52. }
  53. pkgInfo.FileName = header.Filename
  54. pkgInfo.SaveDir = filepath.Join(conf.Conf.Property.Package.SavePath, saveDir)
  55. pkgInfo.ClientType = clientType
  56. pkgInfo.Channel = channel
  57. pkgInfo.ApkName = apkName
  58. err = svr.PackageUpload(file, pkgInfo)
  59. if err != nil {
  60. res["message"] = fmt.Sprintf("%v", err)
  61. c.JSONMap(res, err)
  62. return
  63. }
  64. c.JSONMap(res, nil)
  65. }
  66. func packageList(c *bm.Context) {
  67. var (
  68. clientType = strings.ToLower(c.Request.FormValue("client_type"))
  69. appName = c.Request.Form.Get("app_name")
  70. pipelineID = c.Request.Form.Get("pipeline_id")
  71. saveDir = filepath.Join(clientType, appName, pipelineID)
  72. )
  73. res := map[string]interface{}{}
  74. res["message"] = "success"
  75. saveDir = filepath.Join(conf.Conf.Property.Package.SavePath, saveDir)
  76. if clientType == "" || appName == "" || pipelineID == "" {
  77. errMsg := "client_type, app_name, pipeline_id can not be null"
  78. log.Error(errMsg)
  79. res["message"] = errMsg
  80. c.JSONMap(res, ecode.RequestErr)
  81. return
  82. }
  83. if clientType != "ios" && clientType != "android" {
  84. errMsg := "client_type must be 'ios' or 'android'"
  85. log.Error(errMsg)
  86. res["message"] = errMsg
  87. c.JSONMap(res, ecode.RequestErr)
  88. return
  89. }
  90. fileList, err := svr.PackageList(saveDir)
  91. if err != nil {
  92. res["message"] = fmt.Sprintf("%v", err)
  93. c.JSONMap(res, err)
  94. return
  95. }
  96. c.JSON(fileList, nil)
  97. }