feed.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. cdm "go-common/app/interface/main/app-card/model"
  6. "go-common/app/interface/main/app-card/model/card"
  7. "go-common/app/interface/main/app-card/model/card/ai"
  8. "go-common/app/interface/main/app-card/model/card/operate"
  9. "go-common/app/interface/main/app-feed/model"
  10. "go-common/app/interface/main/app-feed/model/feed"
  11. "go-common/library/ecode"
  12. bm "go-common/library/net/http/blademaster"
  13. )
  14. const (
  15. _headerBuvid = "Buvid"
  16. _headerDisplayID = "Display-ID"
  17. _headerDeviceID = "Device-ID"
  18. _androidFnvalBuild = 5325000
  19. _iosFnvalBuild = 8160
  20. _iosQnBuildGt = 8170
  21. _iosQnBuildLt = 8190
  22. _androidQnBuildLt = 5335000
  23. _qn480 = 32
  24. )
  25. func feedIndex(c *bm.Context) {
  26. var mid int64
  27. params := c.Request.Form
  28. header := c.Request.Header
  29. if midInter, ok := c.Get("mid"); ok {
  30. mid = midInter.(int64)
  31. }
  32. // get params
  33. mobiApp := params.Get("mobi_app")
  34. device := params.Get("device")
  35. platform := params.Get("platform")
  36. network := params.Get("network")
  37. buildStr := params.Get("build")
  38. idxStr := params.Get("idx")
  39. pullStr := params.Get("pull")
  40. styleStr := params.Get("style")
  41. loginEventStr := params.Get("login_event")
  42. openEvent := params.Get("open_event")
  43. bannerHash := params.Get("banner_hash")
  44. adExtra := params.Get("ad_extra")
  45. qnStr := params.Get("qn")
  46. interest := params.Get("interest")
  47. flushStr := params.Get("flush")
  48. autoplayCard, _ := strconv.Atoi(params.Get("autoplay_card"))
  49. fnver, _ := strconv.Atoi(params.Get("fnver"))
  50. fnval, _ := strconv.Atoi(params.Get("fnval"))
  51. // check params
  52. build, err := strconv.Atoi(buildStr)
  53. if err != nil {
  54. c.JSON(nil, ecode.RequestErr)
  55. return
  56. }
  57. plat := model.Plat(mobiApp, device)
  58. if (model.IsAndroid(plat) && build <= _androidFnvalBuild) || (model.IsIOSNormal(plat) && build <= _iosFnvalBuild) {
  59. fnval = 0
  60. }
  61. style, _ := strconv.Atoi(styleStr)
  62. flush, _ := strconv.Atoi(flushStr)
  63. // get audit data, if check audit hit.
  64. is, ok := feedSvc.Audit(c, mobiApp, plat, build)
  65. if ok {
  66. c.JSON(is, nil)
  67. return
  68. }
  69. buvid := header.Get(_headerBuvid)
  70. disid := header.Get(_headerDisplayID)
  71. dvcid := header.Get(_headerDeviceID)
  72. // page
  73. idx, err := strconv.ParseInt(idxStr, 10, 64)
  74. if err != nil || idx < 0 {
  75. idx = 0
  76. }
  77. // pull default
  78. pull, err := strconv.ParseBool(pullStr)
  79. if err != nil {
  80. pull = true
  81. }
  82. // login event
  83. loginEvent, err := strconv.Atoi(loginEventStr)
  84. if err != nil {
  85. loginEvent = 0
  86. }
  87. // qn
  88. qn, _ := strconv.Atoi(qnStr)
  89. now := time.Now()
  90. // index
  91. data, userFeature, isRcmd, newUser, code, feedclean, autoPlayInfoc, err := feedSvc.Index(c, mid, plat, build, buvid, network, mobiApp, device, platform, openEvent, loginEvent, idx, pull, now, bannerHash, adExtra, qn, interest, style, flush, fnver, fnval, autoplayCard)
  92. res := map[string]interface{}{
  93. "data": data,
  94. "config": map[string]interface{}{
  95. "feed_clean_abtest": feedclean,
  96. },
  97. }
  98. c.JSONMap(res, err)
  99. if err != nil {
  100. return
  101. }
  102. // infoc
  103. items := make([]*ai.Item, 0, len(data))
  104. for _, item := range data {
  105. items = append(items, item.AI)
  106. }
  107. feedSvc.IndexInfoc(c, mid, plat, build, buvid, disid, "/x/feed/index", userFeature, style, code, items, isRcmd, pull, newUser, now, "", dvcid, network, flush, autoPlayInfoc, 0)
  108. }
  109. func feedUpper(c *bm.Context) {
  110. var mid int64
  111. params := c.Request.Form
  112. midInter, _ := c.Get("mid")
  113. mid = midInter.(int64)
  114. // get params
  115. mobiApp := params.Get("mobi_app")
  116. device := params.Get("device")
  117. buildStr := params.Get("build")
  118. pnStr := params.Get("pn")
  119. psStr := params.Get("ps")
  120. // check params
  121. build, err := strconv.Atoi(buildStr)
  122. if err != nil {
  123. c.JSON(nil, ecode.RequestErr)
  124. return
  125. }
  126. // check page
  127. pn, err := strconv.Atoi(pnStr)
  128. if err != nil || pn < 1 {
  129. pn = 1
  130. }
  131. ps, err := strconv.Atoi(psStr)
  132. if err != nil || ps < 1 {
  133. ps = 20
  134. } else if ps > 200 {
  135. ps = 200
  136. }
  137. plat := model.Plat(mobiApp, device)
  138. now := time.Now()
  139. uas, _ := feedSvc.Upper(c, mid, plat, build, pn, ps, now)
  140. data := map[string]interface{}{}
  141. if len(uas) != 0 {
  142. data["item"] = uas
  143. } else {
  144. data["item"] = []struct{}{}
  145. }
  146. uls, count := feedSvc.UpperLive(c, mid)
  147. if len(uls) != 0 {
  148. data["live"] = struct {
  149. Item []*feed.Item `json:"item"`
  150. Count int `json:"count"`
  151. Conut int `json:"conut"`
  152. }{uls, count, count}
  153. }
  154. c.JSON(data, nil)
  155. }
  156. func feedUpperArchive(c *bm.Context) {
  157. var mid int64
  158. params := c.Request.Form
  159. midInter, _ := c.Get("mid")
  160. mid = midInter.(int64)
  161. // get params
  162. mobiApp := params.Get("mobi_app")
  163. device := params.Get("device")
  164. buildStr := params.Get("build")
  165. pnStr := params.Get("pn")
  166. psStr := params.Get("ps")
  167. // check params
  168. build, err := strconv.Atoi(buildStr)
  169. if err != nil {
  170. c.JSON(nil, ecode.RequestErr)
  171. return
  172. }
  173. // check page
  174. pn, err := strconv.Atoi(pnStr)
  175. if err != nil || pn < 1 {
  176. pn = 1
  177. }
  178. ps, err := strconv.Atoi(psStr)
  179. if err != nil || ps < 1 {
  180. ps = 20
  181. } else if ps > 200 {
  182. ps = 200
  183. }
  184. plat := model.Plat(mobiApp, device)
  185. now := time.Now()
  186. uas, _ := feedSvc.UpperArchive(c, mid, plat, build, pn, ps, now)
  187. data := map[string]interface{}{}
  188. if len(uas) != 0 {
  189. data["item"] = uas
  190. } else {
  191. data["item"] = []struct{}{}
  192. }
  193. c.JSON(data, nil)
  194. }
  195. func feedUpperBangumi(c *bm.Context) {
  196. var mid int64
  197. params := c.Request.Form
  198. midInter, _ := c.Get("mid")
  199. mid = midInter.(int64)
  200. // get params
  201. mobiApp := params.Get("mobi_app")
  202. device := params.Get("device")
  203. buildStr := params.Get("build")
  204. pnStr := params.Get("pn")
  205. psStr := params.Get("ps")
  206. // check params
  207. build, err := strconv.Atoi(buildStr)
  208. if err != nil {
  209. c.JSON(nil, ecode.RequestErr)
  210. return
  211. }
  212. // check page
  213. pn, err := strconv.Atoi(pnStr)
  214. if err != nil || pn < 1 {
  215. pn = 1
  216. }
  217. ps, err := strconv.Atoi(psStr)
  218. if err != nil || ps < 1 {
  219. ps = 20
  220. } else if ps > 200 {
  221. ps = 200
  222. }
  223. plat := model.Plat(mobiApp, device)
  224. now := time.Now()
  225. uas, _ := feedSvc.UpperBangumi(c, mid, plat, build, pn, ps, now)
  226. data := map[string]interface{}{}
  227. if len(uas) != 0 {
  228. data["item"] = uas
  229. } else {
  230. data["item"] = []struct{}{}
  231. }
  232. c.JSON(data, nil)
  233. }
  234. func feedUpperArticle(c *bm.Context) {
  235. var mid int64
  236. params := c.Request.Form
  237. midInter, _ := c.Get("mid")
  238. mid = midInter.(int64)
  239. // get params
  240. mobiApp := params.Get("mobi_app")
  241. device := params.Get("device")
  242. buildStr := params.Get("build")
  243. pnStr := params.Get("pn")
  244. psStr := params.Get("ps")
  245. // check params
  246. build, err := strconv.Atoi(buildStr)
  247. if err != nil {
  248. c.JSON(nil, ecode.RequestErr)
  249. return
  250. }
  251. // check page
  252. pn, err := strconv.Atoi(pnStr)
  253. if err != nil || pn < 1 {
  254. pn = 1
  255. }
  256. ps, err := strconv.Atoi(psStr)
  257. if err != nil || ps < 1 {
  258. ps = 20
  259. } else if ps > 200 {
  260. ps = 200
  261. }
  262. plat := model.Plat(mobiApp, device)
  263. now := time.Now()
  264. uas, _ := feedSvc.UpperArticle(c, mid, plat, build, pn, ps, now)
  265. data := map[string]interface{}{}
  266. if len(uas) != 0 {
  267. data["item"] = uas
  268. } else {
  269. data["item"] = []struct{}{}
  270. }
  271. c.JSON(data, nil)
  272. }
  273. func feedUnreadCount(c *bm.Context) {
  274. var mid int64
  275. params := c.Request.Form
  276. midInter, _ := c.Get("mid")
  277. mid = midInter.(int64)
  278. // get params
  279. mobiApp := params.Get("mobi_app")
  280. device := params.Get("device")
  281. buildStr := params.Get("build")
  282. // check params
  283. build, err := strconv.Atoi(buildStr)
  284. if err != nil {
  285. c.JSON(nil, ecode.RequestErr)
  286. return
  287. }
  288. plat := model.Plat(mobiApp, device)
  289. total, feedCount, articleCount := feedSvc.UnreadCount(c, mid, plat, build, time.Now())
  290. c.JSON(struct {
  291. Total int `json:"total"`
  292. Count int `json:"count"`
  293. Article int `json:"article"`
  294. }{total, feedCount, articleCount}, nil)
  295. }
  296. func feedDislike(c *bm.Context) {
  297. var mid int64
  298. params := c.Request.Form
  299. header := c.Request.Header
  300. if midInter, ok := c.Get("mid"); ok {
  301. mid = midInter.(int64)
  302. }
  303. gt := params.Get("goto")
  304. if gt == "" {
  305. c.JSON(nil, ecode.RequestErr)
  306. return
  307. }
  308. id, _ := strconv.ParseInt(params.Get("id"), 10, 64)
  309. reasonID, _ := strconv.ParseInt(params.Get("reason_id"), 10, 64)
  310. cmreasonID, _ := strconv.ParseInt(params.Get("cm_reason_id"), 10, 64)
  311. feedbackID, _ := strconv.ParseInt(params.Get("feedback_id"), 10, 64)
  312. upperID, _ := strconv.ParseInt(params.Get("mid"), 10, 64)
  313. rid, _ := strconv.ParseInt(params.Get("rid"), 10, 64)
  314. tagID, _ := strconv.ParseInt(params.Get("tag_id"), 10, 64)
  315. adcb := params.Get("ad_cb")
  316. buvid := header.Get(_headerBuvid)
  317. if buvid == "" && mid == 0 {
  318. c.JSON(nil, ecode.RequestErr)
  319. return
  320. }
  321. c.JSON(nil, feedSvc.Dislike(c, mid, id, buvid, gt, reasonID, cmreasonID, feedbackID, upperID, rid, tagID, adcb, time.Now()))
  322. }
  323. func feedDislikeCancel(c *bm.Context) {
  324. var mid int64
  325. params := c.Request.Form
  326. header := c.Request.Header
  327. if midInter, ok := c.Get("mid"); ok {
  328. mid = midInter.(int64)
  329. }
  330. gt := params.Get("goto")
  331. if gt == "" {
  332. c.JSON(nil, ecode.RequestErr)
  333. return
  334. }
  335. id, _ := strconv.ParseInt(params.Get("id"), 10, 64)
  336. reasonID, _ := strconv.ParseInt(params.Get("reason_id"), 10, 64)
  337. cmreasonID, _ := strconv.ParseInt(params.Get("cm_reason_id"), 10, 64)
  338. feedbackID, _ := strconv.ParseInt(params.Get("feedback_id"), 10, 64)
  339. upperID, _ := strconv.ParseInt(params.Get("mid"), 10, 64)
  340. rid, _ := strconv.ParseInt(params.Get("rid"), 10, 64)
  341. tagID, _ := strconv.ParseInt(params.Get("tag_id"), 10, 64)
  342. adcb := params.Get("ad_cb")
  343. buvid := header.Get(_headerBuvid)
  344. if buvid == "" && mid == 0 {
  345. c.JSON(nil, ecode.RequestErr)
  346. return
  347. }
  348. c.JSON(nil, feedSvc.DislikeCancel(c, mid, id, buvid, gt, reasonID, cmreasonID, feedbackID, upperID, rid, tagID, adcb, time.Now()))
  349. }
  350. func feedUpperRecent(c *bm.Context) {
  351. var mid int64
  352. params := c.Request.Form
  353. if midInter, ok := c.Get("mid"); ok {
  354. mid = midInter.(int64)
  355. }
  356. aidStr := params.Get("param")
  357. aid, err := strconv.ParseInt(aidStr, 10, 64)
  358. if err != nil {
  359. c.JSON(nil, ecode.RequestErr)
  360. return
  361. }
  362. upperStr := params.Get("vmid")
  363. upperID, err := strconv.ParseInt(upperStr, 10, 64)
  364. if err != nil {
  365. c.JSON(nil, ecode.RequestErr)
  366. return
  367. }
  368. c.JSON(struct {
  369. Item []*feed.Item `json:"item"`
  370. }{feedSvc.UpperRecent(c, mid, upperID, aid, time.Now())}, nil)
  371. }
  372. func feedIndexTab(c *bm.Context) {
  373. var (
  374. id int64
  375. items []*feed.Item
  376. isBnj bool
  377. bnjDays int
  378. cover string
  379. err error
  380. mid int64
  381. )
  382. params := c.Request.Form
  383. if midInter, ok := c.Get("mid"); ok {
  384. mid = midInter.(int64)
  385. }
  386. now := time.Now()
  387. idStr := params.Get("id")
  388. mobiApp := params.Get("mobi_app")
  389. device := params.Get("device")
  390. buildStr := params.Get("build")
  391. // check params
  392. build, err := strconv.Atoi(buildStr)
  393. if err != nil {
  394. c.JSON(nil, ecode.RequestErr)
  395. return
  396. }
  397. plat := model.Plat(mobiApp, device)
  398. if id, _ = strconv.ParseInt(idStr, 10, 64); id <= 0 {
  399. c.JSON(struct {
  400. Tab []*operate.Menu `json:"tab"`
  401. }{feedSvc.Menus(c, plat, build, now)}, nil)
  402. return
  403. }
  404. items, cover, isBnj, bnjDays, err = feedSvc.Actives(c, id, mid, now)
  405. c.JSON(struct {
  406. Cover string `json:"cover"`
  407. IsBnj bool `json:"is_bnj,omitempty"`
  408. BnjDays int `json:"bnj_days,omitempty"`
  409. Item []*feed.Item `json:"item"`
  410. }{cover, isBnj, bnjDays, items}, err)
  411. }
  412. func feedIndex2(c *bm.Context) {
  413. var mid int64
  414. if midInter, ok := c.Get("mid"); ok {
  415. mid = midInter.(int64)
  416. }
  417. header := c.Request.Header
  418. buvid := header.Get(_headerBuvid)
  419. disid := header.Get(_headerDisplayID)
  420. dvcid := header.Get(_headerDeviceID)
  421. param := &feed.IndexParam{}
  422. // get params
  423. if err := c.Bind(param); err != nil {
  424. c.JSON(nil, ecode.RequestErr)
  425. return
  426. }
  427. _, ok := cdm.Columnm[param.Column]
  428. if !ok {
  429. c.JSON(nil, ecode.RequestErr)
  430. return
  431. }
  432. // 兼容老的style逻辑,3为新单列
  433. style := int(cdm.Columnm[param.Column])
  434. if style == 1 {
  435. style = 3
  436. }
  437. // check params
  438. plat := model.Plat(param.MobiApp, param.Device)
  439. // get audit data, if check audit hit.
  440. if data, ok := feedSvc.Audit2(c, param.MobiApp, plat, param.Build, param.Column); ok {
  441. c.JSON(struct {
  442. Item []card.Handler `json:"items"`
  443. }{Item: data}, nil)
  444. return
  445. }
  446. if (model.IsAndroid(plat) && param.Build <= _androidFnvalBuild) || (model.IsIOSNormal(plat) && param.Build <= _iosFnvalBuild) {
  447. param.Fnval = 0
  448. }
  449. if (model.IsAndroid(plat) && param.Build > _androidFnvalBuild && param.Build < _androidQnBuildLt) || (model.IsIOSNormal(plat) && param.Build > _iosQnBuildGt && param.Build <= _iosQnBuildLt) || param.Qn <= 0 {
  450. param.Qn = _qn480
  451. }
  452. now := time.Now()
  453. // index
  454. plat = model.PlatAPPBuleChange(plat)
  455. data, config, infc, err := feedSvc.Index2(c, buvid, mid, plat, param, style, now)
  456. c.JSON(struct {
  457. Item []card.Handler `json:"items"`
  458. Config *feed.Config `json:"config"`
  459. }{Item: data, Config: config}, err)
  460. if err != nil {
  461. return
  462. }
  463. // infoc
  464. items := make([]*ai.Item, 0, len(data))
  465. for _, item := range data {
  466. items = append(items, item.Get().Rcmd)
  467. }
  468. feedSvc.IndexInfoc(c, mid, plat, param.Build, buvid, disid, "/x/feed/index", infc.UserFeature, style, infc.Code, items, infc.IsRcmd, param.Pull, infc.NewUser, now, "", dvcid, param.Network, param.Flush, infc.AutoPlayInfoc, param.DeviceType)
  469. }
  470. func feedIndexTab2(c *bm.Context) {
  471. var (
  472. id int64
  473. items []card.Handler
  474. isBnj bool
  475. bnjDays int
  476. cover string
  477. err error
  478. mid int64
  479. )
  480. params := c.Request.Form
  481. if midInter, ok := c.Get("mid"); ok {
  482. mid = midInter.(int64)
  483. }
  484. now := time.Now()
  485. idStr := params.Get("id")
  486. mobiApp := params.Get("mobi_app")
  487. device := params.Get("device")
  488. forceHost, _ := strconv.Atoi(params.Get("force_host"))
  489. buildStr := params.Get("build")
  490. // check params
  491. build, err := strconv.Atoi(buildStr)
  492. if err != nil {
  493. c.JSON(nil, ecode.RequestErr)
  494. return
  495. }
  496. plat := model.Plat(mobiApp, device)
  497. if id, _ = strconv.ParseInt(idStr, 10, 64); id <= 0 {
  498. c.JSON(struct {
  499. Tab []*operate.Menu `json:"tab"`
  500. }{feedSvc.Menus(c, plat, build, now)}, nil)
  501. return
  502. }
  503. items, cover, isBnj, bnjDays, err = feedSvc.Actives2(c, id, mid, mobiApp, plat, build, forceHost, now)
  504. c.JSON(struct {
  505. Cover string `json:"cover"`
  506. IsBnj bool `json:"is_bnj,omitempty"`
  507. BnjDays int `json:"bnj_days,omitempty"`
  508. Item []card.Handler `json:"items"`
  509. }{cover, isBnj, bnjDays, items}, err)
  510. }
  511. func feedIndexConverge(c *bm.Context) {
  512. var (
  513. mid int64
  514. title string
  515. cover string
  516. uri string
  517. )
  518. if midInter, ok := c.Get("mid"); ok {
  519. mid = midInter.(int64)
  520. }
  521. param := &feed.ConvergeParam{}
  522. if err := c.Bind(param); err != nil {
  523. return
  524. }
  525. plat := model.Plat(param.MobiApp, param.Device)
  526. if (model.IsAndroid(plat) && param.Build <= _androidFnvalBuild) || (model.IsIOSNormal(plat) && param.Build <= _iosFnvalBuild) {
  527. param.Fnval = 0
  528. }
  529. data, converge, err := feedSvc.Converge(c, mid, plat, param, time.Now())
  530. if converge != nil {
  531. title = converge.Title
  532. cover = converge.Cover
  533. uri = converge.URI
  534. }
  535. c.JSON(struct {
  536. Items []card.Handler `json:"items,omitempty"`
  537. Title string `json:"title,omitempty"`
  538. Cover string `json:"cover,omitempty"`
  539. Param string `json:"param,omitempty"`
  540. URI string `json:"uri,omitempty"`
  541. }{Items: data, Title: title, Cover: cover, Param: strconv.FormatInt(param.ID, 10), URI: uri}, err)
  542. }