show.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/app/interface/main/app-show/model"
  6. "go-common/app/interface/main/app-show/model/show"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/net/metadata"
  11. )
  12. const (
  13. _headerBuvid = "Buvid"
  14. _headerDisplayID = "Display-ID"
  15. )
  16. func shows(c *bm.Context) {
  17. var (
  18. params = c.Request.Form
  19. header = c.Request.Header
  20. )
  21. // get params
  22. mobiApp := params.Get("mobi_app")
  23. mobiApp = model.MobiAPPBuleChange(mobiApp)
  24. buildStr := params.Get("build")
  25. channel := params.Get("channel")
  26. ak := params.Get("access_key")
  27. // check params
  28. build, err := strconv.Atoi(buildStr)
  29. if err != nil {
  30. log.Error("strconv.Atoi(%s) error(%v)", buildStr, err)
  31. c.JSON(nil, ecode.RequestErr)
  32. return
  33. }
  34. device := params.Get("device")
  35. plat := model.Plat(mobiApp, device)
  36. // get audit data, if check audit hit.
  37. ss, ok := showSvc.Audit(c, mobiApp, plat, build)
  38. if ok {
  39. returnJSON(c, ss, nil)
  40. return
  41. }
  42. network := params.Get("network")
  43. ip := metadata.String(c, metadata.RemoteIP)
  44. buvid := header.Get(_headerBuvid)
  45. disid := header.Get(_headerDisplayID)
  46. var mid int64
  47. if midInter, ok := c.Get("mid"); ok {
  48. mid = midInter.(int64)
  49. }
  50. // display
  51. ss = showSvc.Display(c, mid, plat, build, buvid, channel, ip, ak, network, mobiApp, device, "hans", "", false, time.Now())
  52. returnJSON(c, ss, nil)
  53. // infoc
  54. if len(ss) == 0 {
  55. return
  56. }
  57. showSvc.Infoc(mid, plat, buvid, disid, ip, "/x/v2/show", ss[0].Body, time.Now())
  58. }
  59. func showsRegion(c *bm.Context) {
  60. var (
  61. params = c.Request.Form
  62. header = c.Request.Header
  63. )
  64. // get params
  65. mobiApp := params.Get("mobi_app")
  66. mobiApp = model.MobiAPPBuleChange(mobiApp)
  67. buildStr := params.Get("build")
  68. channel := params.Get("channel")
  69. ak := params.Get("access_key")
  70. // check params
  71. build, err := strconv.Atoi(buildStr)
  72. if err != nil {
  73. log.Error("strconv.Atoi(%s) error(%v)", buildStr, err)
  74. c.JSON(nil, ecode.RequestErr)
  75. return
  76. }
  77. device := params.Get("device")
  78. plat := model.Plat(mobiApp, device)
  79. // get audit data, if check audit hit.
  80. ss, ok := showSvc.Audit(c, mobiApp, plat, build)
  81. if !ok {
  82. ip := metadata.String(c, metadata.RemoteIP)
  83. buvid := header.Get(_headerBuvid)
  84. network := params.Get("network")
  85. var mid int64
  86. if midInter, ok := c.Get("mid"); ok {
  87. mid = midInter.(int64)
  88. }
  89. // display
  90. language := params.Get("lang")
  91. ss = showSvc.RegionDisplay(c, mid, plat, build, buvid, channel, ip, ak, network, mobiApp, device, language, "", false, time.Now())
  92. }
  93. res := map[string]interface{}{
  94. "data": ss,
  95. }
  96. returnDataJSON(c, res, 25, nil)
  97. }
  98. func showsIndex(c *bm.Context) {
  99. var (
  100. params = c.Request.Form
  101. header = c.Request.Header
  102. )
  103. // get params
  104. mobiApp := params.Get("mobi_app")
  105. mobiApp = model.MobiAPPBuleChange(mobiApp)
  106. buildStr := params.Get("build")
  107. channel := params.Get("channel")
  108. ak := params.Get("access_key")
  109. // check params
  110. build, err := strconv.Atoi(buildStr)
  111. if err != nil {
  112. log.Error("strconv.Atoi(%s) error(%v)", buildStr, err)
  113. c.JSON(nil, ecode.RequestErr)
  114. return
  115. }
  116. device := params.Get("device")
  117. plat := model.Plat(mobiApp, device)
  118. // get audit data, if check audit hit.
  119. ss, ok := showSvc.Audit(c, mobiApp, plat, build)
  120. if !ok {
  121. ip := metadata.String(c, metadata.RemoteIP)
  122. buvid := header.Get(_headerBuvid)
  123. network := params.Get("network")
  124. var mid int64
  125. if midInter, ok := c.Get("mid"); ok {
  126. mid = midInter.(int64)
  127. }
  128. // display
  129. language := params.Get("lang")
  130. adExtra := params.Get("ad_extra")
  131. ss = showSvc.Index(c, mid, plat, build, buvid, channel, ip, ak, network, mobiApp, device, language, adExtra, false, time.Now())
  132. }
  133. res := map[string]interface{}{
  134. "data": ss,
  135. }
  136. returnDataJSON(c, res, 25, nil)
  137. }
  138. func showTemps(c *bm.Context) {
  139. var (
  140. params = c.Request.Form
  141. header = c.Request.Header
  142. )
  143. // get params
  144. mobiApp := params.Get("mobi_app")
  145. // check params
  146. device := params.Get("device")
  147. plat := model.Plat(mobiApp, device)
  148. ip := metadata.String(c, metadata.RemoteIP)
  149. var mid int64
  150. if midInter, ok := c.Get("mid"); ok {
  151. mid = midInter.(int64)
  152. }
  153. // display
  154. data := showSvc.Display(c, mid, plat, 0, header.Get(_headerBuvid), "", ip, "", "wifi", mobiApp, device, "hans", "", true, time.Now())
  155. returnJSON(c, data, nil)
  156. }
  157. func showChange(c *bm.Context) {
  158. params := c.Request.Form
  159. header := c.Request.Header
  160. // get params
  161. mobiApp := params.Get("mobi_app")
  162. mobiApp = model.MobiAPPBuleChange(mobiApp)
  163. randStr := params.Get("rand")
  164. buildStr := params.Get("build")
  165. // check params
  166. rand, err := strconv.Atoi(randStr)
  167. if err != nil {
  168. log.Error("strconv.Atoi(%s) error(%v)", randStr, err)
  169. c.JSON(nil, ecode.RequestErr)
  170. return
  171. }
  172. device := params.Get("device")
  173. plat := model.Plat(mobiApp, device)
  174. // normal data
  175. ip := metadata.String(c, metadata.RemoteIP)
  176. buvid := header.Get(_headerBuvid)
  177. disid := header.Get(_headerDisplayID)
  178. network := params.Get("network")
  179. var mid int64
  180. if midInter, ok := c.Get("mid"); ok {
  181. mid = midInter.(int64)
  182. }
  183. build, _ := strconv.Atoi(buildStr)
  184. // change
  185. sis := showSvc.Change(c, mid, build, plat, rand, buvid, ip, network, mobiApp, device)
  186. returnJSON(c, sis, nil)
  187. // infoc
  188. showSvc.Infoc(mid, plat, buvid, disid, ip, "/x/v2/show/change", sis, time.Now())
  189. }
  190. // showRegionChange
  191. func showRegionChange(c *bm.Context) {
  192. params := c.Request.Form
  193. mobiApp := params.Get("mobi_app")
  194. mobiApp = model.MobiAPPBuleChange(mobiApp)
  195. device := params.Get("device")
  196. buildStr := params.Get("build")
  197. plat := model.Plat(mobiApp, device)
  198. // get params
  199. randStr := params.Get("rand")
  200. // check params
  201. rand, err := strconv.Atoi(randStr)
  202. if err != nil {
  203. log.Error("strconv.Atoi(%s) error(%v)", randStr, err)
  204. c.JSON(nil, ecode.RequestErr)
  205. return
  206. }
  207. ridStr := params.Get("rid")
  208. rid, err := strconv.Atoi(ridStr)
  209. if err != nil {
  210. log.Error("ridStr(%s) error(%v)", ridStr, err)
  211. c.JSON(nil, ecode.RequestErr)
  212. return
  213. }
  214. build, _ := strconv.Atoi(buildStr)
  215. data := showSvc.RegionChange(c, rid, rand, plat, build, mobiApp)
  216. returnJSON(c, data, nil)
  217. }
  218. // showBangumiChange
  219. func showBangumiChange(c *bm.Context) {
  220. params := c.Request.Form
  221. mobiApp := params.Get("mobi_app")
  222. mobiApp = model.MobiAPPBuleChange(mobiApp)
  223. device := params.Get("device")
  224. plat := model.Plat(mobiApp, device)
  225. // get params
  226. randStr := params.Get("rand")
  227. // check params
  228. rand, err := strconv.Atoi(randStr)
  229. if err != nil {
  230. log.Error("strconv.Atoi(%s) error(%v)", randStr, err)
  231. c.JSON(nil, ecode.RequestErr)
  232. return
  233. }
  234. data := showSvc.BangumiChange(c, rand, plat)
  235. returnJSON(c, data, nil)
  236. }
  237. // showArticleChange
  238. func showArticleChange(c *bm.Context) {
  239. data := []*show.Item{}
  240. returnJSON(c, data, nil)
  241. }
  242. // showDislike
  243. func showDislike(c *bm.Context) {
  244. var (
  245. params = c.Request.Form
  246. header = c.Request.Header
  247. mid int64
  248. )
  249. // get params
  250. mobiApp := params.Get("mobi_app")
  251. mobiApp = model.MobiAPPBuleChange(mobiApp)
  252. device := params.Get("device")
  253. plat := model.Plat(mobiApp, device)
  254. if midInter, ok := c.Get("mid"); ok {
  255. mid = midInter.(int64)
  256. }
  257. idStr := params.Get("id")
  258. gt := params.Get("goto")
  259. if !model.IsGoto(gt) {
  260. c.JSON(nil, ecode.RequestErr)
  261. return
  262. }
  263. // normal data
  264. ip := metadata.String(c, metadata.RemoteIP)
  265. buvid := header.Get(_headerBuvid)
  266. disid := header.Get(_headerDisplayID)
  267. // parse id
  268. id, err := strconv.ParseInt(idStr, 10, 64)
  269. if err != nil {
  270. log.Error("strconv.Atoi(%s) error(%v)", idStr, err)
  271. c.JSON(nil, ecode.RequestErr)
  272. return
  273. }
  274. // change
  275. si := showSvc.Dislike(c, mid, plat, id, buvid, mobiApp, device, gt, ip)
  276. returnJSON(c, si, nil)
  277. // infoc
  278. showSvc.Infoc(mid, plat, buvid, disid, ip, "/x/v2/show/change/dislike", []*show.Item{si}, time.Now())
  279. }
  280. func showWidget(c *bm.Context) {
  281. params := c.Request.Form
  282. mobiApp := params.Get("mobi_app")
  283. device := params.Get("device")
  284. plat := model.Plat(mobiApp, device)
  285. buildStr := params.Get("build")
  286. build, err := strconv.Atoi(buildStr)
  287. if err != nil {
  288. log.Error("strconv.Atoi(%s) error(%v)", buildStr, err)
  289. c.JSON(nil, ecode.RequestErr)
  290. return
  291. }
  292. var data []*show.Item
  293. if ss, ok := showSvc.AuditChild(c, mobiApp, plat, build); ok {
  294. if len(ss) > 3 {
  295. data = ss[:3]
  296. } else {
  297. data = ss
  298. }
  299. returnJSON(c, data, nil)
  300. return
  301. }
  302. data = showSvc.Widget(c, plat)
  303. returnJSON(c, data, nil)
  304. }
  305. // show live change
  306. func showLiveChange(c *bm.Context) {
  307. params := c.Request.Form
  308. // get params
  309. randStr := params.Get("rand")
  310. ak := params.Get("access_key")
  311. rand, err := strconv.Atoi(randStr)
  312. if err != nil {
  313. log.Error("strconv.Atoi(%s) error(%v)", randStr, err)
  314. c.JSON(nil, ecode.RequestErr)
  315. return
  316. }
  317. var mid int64
  318. if midInter, ok := c.Get("mid"); ok {
  319. mid = midInter.(int64)
  320. }
  321. // change
  322. ip := metadata.String(c, metadata.RemoteIP)
  323. data := showSvc.LiveChange(c, mid, ak, ip, rand, time.Now())
  324. returnJSON(c, data, nil)
  325. }
  326. // popular hot tab popular
  327. func popular(c *bm.Context) {
  328. var (
  329. params = c.Request.Form
  330. header = c.Request.Header
  331. mid int64
  332. )
  333. mobiApp := params.Get("mobi_app")
  334. device := params.Get("device")
  335. buildStr := params.Get("build")
  336. idxStr := params.Get("idx")
  337. loginEventStr := params.Get("login_event")
  338. lastParam := params.Get("last_param")
  339. build, err := strconv.Atoi(buildStr)
  340. if err != nil {
  341. c.JSON(nil, ecode.RequestErr)
  342. return
  343. }
  344. plat := model.Plat(mobiApp, device)
  345. loginEvent, err := strconv.Atoi(loginEventStr)
  346. if err != nil {
  347. loginEvent = 0
  348. }
  349. idx, err := strconv.ParseInt(idxStr, 10, 64)
  350. if err != nil || idx < 0 {
  351. idx = 0
  352. }
  353. now := time.Now()
  354. if midInter, ok := c.Get("mid"); ok {
  355. mid = midInter.(int64)
  356. }
  357. buvid := header.Get(_headerBuvid)
  358. // get audit data, if check audit hit.
  359. data, ok := showSvc.AuditFeed(c, mobiApp, plat, build)
  360. if !ok {
  361. data = showSvc.FeedIndex(c, mid, idx, plat, build, loginEvent, lastParam, mobiApp, device, buvid, now)
  362. }
  363. c.JSON(data, nil)
  364. }
  365. // popular hot tab popular
  366. func popular2(c *bm.Context) {
  367. var (
  368. params = c.Request.Form
  369. header = c.Request.Header
  370. mid int64
  371. )
  372. mobiApp := params.Get("mobi_app")
  373. device := params.Get("device")
  374. buildStr := params.Get("build")
  375. idxStr := params.Get("idx")
  376. loginEventStr := params.Get("login_event")
  377. lastParam := params.Get("last_param")
  378. build, err := strconv.Atoi(buildStr)
  379. if err != nil {
  380. c.JSON(nil, ecode.RequestErr)
  381. return
  382. }
  383. plat := model.Plat(mobiApp, device)
  384. loginEvent, err := strconv.Atoi(loginEventStr)
  385. if err != nil {
  386. loginEvent = 0
  387. }
  388. idx, err := strconv.ParseInt(idxStr, 10, 64)
  389. if err != nil || idx < 0 {
  390. idx = 0
  391. }
  392. now := time.Now()
  393. if midInter, ok := c.Get("mid"); ok {
  394. mid = midInter.(int64)
  395. }
  396. buvid := header.Get(_headerBuvid)
  397. // get audit data, if check audit hit.
  398. data, ok := showSvc.AuditFeed2(c, mobiApp, plat, build)
  399. var (
  400. ver string
  401. )
  402. if !ok {
  403. data, ver, err = showSvc.FeedIndex2(c, mid, idx, plat, build, loginEvent, lastParam, mobiApp, device, buvid, now)
  404. }
  405. config := map[string]interface{}{
  406. "item_title": "当前热门",
  407. }
  408. c.JSONMap(map[string]interface{}{"data": data, "ver": ver, "config": config}, err)
  409. }