version.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/app-resource/model"
  5. "go-common/app/interface/main/app-resource/model/version"
  6. "go-common/library/ecode"
  7. bm "go-common/library/net/http/blademaster"
  8. "github.com/golang/protobuf/proto"
  9. )
  10. // getVersion get version
  11. func getVersion(c *bm.Context) {
  12. params := c.Request.Form
  13. mobiApp := params.Get("mobi_app")
  14. device := params.Get("device")
  15. plat := model.Plat(mobiApp, device)
  16. data, err := verSvc.Version(plat)
  17. c.JSON(data, err)
  18. }
  19. // versionUpdate get versionUpdate
  20. func versionUpdate(c *bm.Context) {
  21. var (
  22. params = c.Request.Form
  23. header = c.Request.Header
  24. )
  25. mobiApp := params.Get("mobi_app")
  26. device := params.Get("device")
  27. plat := model.Plat(mobiApp, device)
  28. buildStr := params.Get("build")
  29. channel := params.Get("channel")
  30. sdkStr := params.Get("sdkint")
  31. platModel := params.Get("model")
  32. oldID := params.Get("old_id")
  33. build, err := strconv.Atoi(buildStr)
  34. if err != nil {
  35. c.JSON(nil, ecode.RequestErr)
  36. return
  37. }
  38. buvid := header.Get(_headerBuvid)
  39. // mobiApp not equal to android or mobiApp is null,default android
  40. if !model.IsAndroid(plat) {
  41. plat = model.PlatAndroid
  42. }
  43. if (plat == model.PlatAndroid) && (build >= 591000 && build <= 599000) {
  44. plat = model.PlatAndroidB
  45. }
  46. data, err := verSvc.VersionUpdate(build, plat, buvid, sdkStr, channel, platModel, oldID)
  47. if err != nil {
  48. c.JSON(nil, ecode.NotModified)
  49. return
  50. }
  51. c.JSON(data, nil)
  52. }
  53. // versionUpdate get versionUpdate
  54. func versionUpdatePb(c *bm.Context) {
  55. var (
  56. params = c.Request.Form
  57. header = c.Request.Header
  58. )
  59. mobiApp := params.Get("mobi_app")
  60. device := params.Get("device")
  61. plat := model.Plat(mobiApp, device)
  62. buildStr := params.Get("build")
  63. channel := params.Get("channel")
  64. sdkStr := params.Get("sdkint")
  65. platModel := params.Get("model")
  66. oldID := params.Get("old_id")
  67. build, err := strconv.Atoi(buildStr)
  68. if err != nil {
  69. c.JSON(nil, ecode.RequestErr)
  70. return
  71. }
  72. buvid := header.Get(_headerBuvid)
  73. // mobiApp not equal to android or mobiApp is null,default android
  74. if !model.IsAndroid(plat) {
  75. plat = model.PlatAndroid
  76. }
  77. data, err := verSvc.VersionUpdate(build, plat, buvid, sdkStr, channel, platModel, oldID)
  78. if err != nil {
  79. c.JSON(nil, ecode.NotModified)
  80. return
  81. }
  82. size, _ := strconv.Atoi(data.Size)
  83. resPb := &version.VerUpdate{
  84. Ver: *proto.String(data.Version),
  85. Build: *proto.Int(data.Build),
  86. Info: *proto.String(data.Desc),
  87. Size: *proto.Int(size),
  88. Url: *proto.String(data.Url),
  89. Hash: *proto.String(data.MD5),
  90. Policy: *proto.Int(data.Policy),
  91. IsForce: *proto.Int(data.IsForce),
  92. Mtime: *proto.Int64(data.Mtime.Time().Unix()),
  93. }
  94. c.JSON(resPb, nil)
  95. }
  96. func versionSo(c *bm.Context) {
  97. params := c.Request.Form
  98. name := params.Get("name")
  99. seedStr := params.Get("seed")
  100. buildStr := params.Get("build")
  101. sdkStr := params.Get("sdkint")
  102. model := params.Get("model")
  103. seed, err := strconv.Atoi(seedStr)
  104. if err != nil {
  105. c.JSON(nil, ecode.RequestErr)
  106. return
  107. }
  108. build, err := strconv.Atoi(buildStr)
  109. if err != nil {
  110. c.JSON(nil, ecode.RequestErr)
  111. return
  112. }
  113. sdkint, _ := strconv.Atoi(sdkStr)
  114. data, err := verSvc.VersionSo(build, seed, sdkint, name, model)
  115. if err != nil {
  116. c.JSON(nil, ecode.NotModified)
  117. return
  118. }
  119. c.JSON(data, nil)
  120. }
  121. // versionRn get versionUpdate
  122. func versionRn(c *bm.Context) {
  123. params := c.Request.Form
  124. deploymentKey := params.Get("deployment_key")
  125. bundleID := params.Get("bundle_id")
  126. version := params.Get("base_version")
  127. data, err := verSvc.VersionRn(version, deploymentKey, bundleID)
  128. c.JSON(data, err)
  129. }