view.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/app/interface/openplatform/article/conf"
  6. artmdl "go-common/app/interface/openplatform/article/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log/infoc"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/net/metadata"
  11. )
  12. func view(c *bm.Context) {
  13. var (
  14. id int64
  15. err error
  16. art *artmdl.Article
  17. params = c.Request.Form
  18. )
  19. idStr := params.Get("id")
  20. id, _ = strconv.ParseInt(idStr, 10, 64)
  21. if id <= 0 {
  22. c.JSON(nil, ecode.RequestErr)
  23. return
  24. }
  25. if art, err = artSrv.Article(c, id); err != nil {
  26. c.JSON(nil, err)
  27. return
  28. }
  29. if art == nil {
  30. c.JSON(nil, ecode.NothingFound)
  31. return
  32. }
  33. c.JSON(art, err)
  34. }
  35. func addView(c *bm.Context) {
  36. var (
  37. mid int64
  38. params = c.Request.Form
  39. page = params.Get("page")
  40. from = params.Get("from")
  41. ip = metadata.String(c, metadata.RemoteIP)
  42. )
  43. if page == "" {
  44. c.JSON(nil, ecode.RequestErr)
  45. return
  46. }
  47. if from == "" {
  48. from = "unknow"
  49. }
  50. if midInter, ok := c.Get("mid"); ok {
  51. mid = midInter.(int64)
  52. }
  53. device := params.Get("device")
  54. mobiApp := params.Get("mobi_app")
  55. plat := artmdl.Plat(mobiApp, device)
  56. build := params.Get("build")
  57. buvid := buvid(c)
  58. // for tianma mainCard -> 7
  59. if from == "mainCard" {
  60. from = "7"
  61. }
  62. ua := c.Request.Header.Get("User-Agent")
  63. referer := c.Request.Header.Get("Referer")
  64. artSrv.ShowInfoc(ip, time.Now(), buvid, mid, plat, page, from, build, ua, referer)
  65. c.JSON(nil, nil)
  66. }
  67. func viewInfo(c *bm.Context) {
  68. var (
  69. id int64
  70. mid int64
  71. data *artmdl.ViewInfo
  72. request = c.Request
  73. params = request.Form
  74. ip = metadata.String(c, metadata.RemoteIP)
  75. err error
  76. )
  77. idStr := params.Get("id")
  78. id, _ = strconv.ParseInt(idStr, 10, 64)
  79. if id == 0 {
  80. c.JSON(nil, ecode.RequestErr)
  81. return
  82. }
  83. if midInter, ok := c.Get("mid"); ok {
  84. mid = midInter.(int64)
  85. }
  86. cheat := cheatInfo(c, mid, id)
  87. device := params.Get("device")
  88. mobiApp := params.Get("mobi_app")
  89. plat := artmdl.Plat(mobiApp, device)
  90. from := params.Get("from")
  91. if data, err = artSrv.ViewInfo(c, mid, id, ip, cheat, plat, from); err != nil {
  92. c.JSON(nil, err)
  93. return
  94. }
  95. buildStr := params.Get("build")
  96. build, _ := strconv.Atoi(buildStr)
  97. buvid := buvid(c)
  98. if from == "articleSlideShow" {
  99. data.Pre, data.Next = artSrv.ViewList(c, id, buvid, "articleSlide", ip, build, plat, mid)
  100. } else {
  101. data.Pre, data.Next = artSrv.ViewList(c, id, buvid, from, ip, build, plat, mid)
  102. }
  103. // for tianma mainCard -> 7
  104. if from == "mainCard" {
  105. from = "7"
  106. }
  107. if from != "articleSlide" {
  108. ua := c.Request.Header.Get("User-Agent")
  109. artSrv.ViewInfoc(mid, plat, build, "doc", from, buvid, id, time.Now(), ua)
  110. artSrv.AIViewInfoc(mid, plat, build, "doc", from, buvid, id, time.Now(), ua)
  111. }
  112. c.JSON(data, nil)
  113. }
  114. func list(c *bm.Context) {
  115. var (
  116. mid int64
  117. request = c.Request
  118. params = request.Form
  119. pn, ps int64
  120. )
  121. midStr := params.Get("mid")
  122. mid, _ = strconv.ParseInt(midStr, 10, 64)
  123. if mid <= 0 {
  124. c.JSON(nil, ecode.RequestErr)
  125. return
  126. }
  127. pnStr := params.Get("pn")
  128. pn, _ = strconv.ParseInt(pnStr, 10, 64)
  129. if pn <= 0 {
  130. pn = 1
  131. }
  132. psStr := params.Get("ps")
  133. ps, _ = strconv.ParseInt(psStr, 10, 64)
  134. if ps <= 0 {
  135. ps = 20
  136. } else if ps > conf.Conf.Article.MaxUpperListPsSize {
  137. ps = conf.Conf.Article.MaxUpperListPsSize
  138. }
  139. c.JSON(artSrv.UpArtMetasAndLists(c, mid, int(pn), int(ps), artmdl.FieldDefault))
  140. }
  141. func earlyArticles(c *bm.Context) {
  142. var (
  143. err error
  144. aid int64
  145. params = c.Request.Form
  146. )
  147. aidStr := params.Get("aid")
  148. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil {
  149. c.JSON(nil, ecode.RequestErr)
  150. return
  151. }
  152. c.JSON(artSrv.MoreArts(c, aid))
  153. }
  154. func moreArts(c *bm.Context) {
  155. var (
  156. err error
  157. aid, mid int64
  158. params = c.Request.Form
  159. )
  160. aidStr := params.Get("aid")
  161. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil {
  162. c.JSON(nil, ecode.RequestErr)
  163. return
  164. }
  165. if midInter, ok := c.Get("mid"); ok {
  166. mid = midInter.(int64)
  167. }
  168. c.JSON(artSrv.Mores(c, aid, mid))
  169. }
  170. func cheatInfo(c *bm.Context, mid, id int64) (res *artmdl.CheatInfo) {
  171. req := c.Request
  172. params := req.Form
  173. res = &artmdl.CheatInfo{
  174. Mid: strconv.FormatInt(mid, 10),
  175. Cvid: strconv.FormatInt(id, 10),
  176. Refer: req.Header.Get("Referer"),
  177. UA: req.Header.Get("User-Agent"),
  178. Ts: strconv.FormatInt(time.Now().Unix(), 10),
  179. IP: metadata.String(c, metadata.RemoteIP),
  180. }
  181. if csid, err := req.Cookie("sid"); err == nil {
  182. res.Sid = csid.Value
  183. }
  184. if params.Get("access_key") == "" {
  185. res.Client = infoc.ClientWeb
  186. if ck, err := req.Cookie("buvid3"); err == nil {
  187. res.Buvid = ck.Value
  188. }
  189. } else {
  190. if params.Get("platform") == "ios" {
  191. if params.Get("device") == "pad" {
  192. res.Client = infoc.ClientIpad
  193. } else {
  194. res.Client = infoc.ClientIphone
  195. }
  196. } else if params.Get("platform") == "android" {
  197. res.Client = infoc.ClientAndroid
  198. }
  199. res.Buvid = req.Header.Get("buvid")
  200. res.Build = params.Get("build")
  201. }
  202. return
  203. }
  204. func actInfo(c *bm.Context) {
  205. var (
  206. request = c.Request
  207. params = request.Form
  208. )
  209. mobiApp := params.Get("mobi_app")
  210. plat := artmdl.Plat(mobiApp, "")
  211. c.JSON(artSrv.ActInfo(c, plat))
  212. }