http.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package http
  2. import (
  3. "net/url"
  4. "strconv"
  5. "go-common/app/interface/main/tv/conf"
  6. appsrv "go-common/app/interface/main/tv/service/app"
  7. auditsrv "go-common/app/interface/main/tv/service/audit"
  8. "go-common/app/interface/main/tv/service/favorite"
  9. gobsrv "go-common/app/interface/main/tv/service/goblin"
  10. hissrv "go-common/app/interface/main/tv/service/history"
  11. "go-common/app/interface/main/tv/service/pgc"
  12. secsrv "go-common/app/interface/main/tv/service/search"
  13. "go-common/app/interface/main/tv/service/thirdp"
  14. "go-common/app/interface/main/tv/service/tvvip"
  15. viewsrv "go-common/app/interface/main/tv/service/view"
  16. "go-common/library/log"
  17. bm "go-common/library/net/http/blademaster"
  18. "go-common/library/net/http/blademaster/middleware/auth"
  19. "go-common/library/net/http/blademaster/middleware/verify"
  20. )
  21. var (
  22. favSvc *favorite.Service
  23. tvSvc *appsrv.Service
  24. viewSvc *viewsrv.Service
  25. auditSvc *auditsrv.Service
  26. gobSvc *gobsrv.Service
  27. secSvc *secsrv.Service
  28. thirdpSvc *thirdp.Service
  29. tvVipSvc *tvvip.Service
  30. authSvc *auth.Auth
  31. vfySvc *verify.Verify
  32. hisSvc *hissrv.Service
  33. pgcSvc *pgc.Service
  34. signCfg *conf.AuditSign
  35. )
  36. // Init init http sever instance.
  37. func Init(c *conf.Config) {
  38. signCfg = c.Cfg.AuditSign
  39. initService(c)
  40. // init outer router
  41. engineOut := bm.NewServer(c.HTTPServer)
  42. engineOut.Use(bm.Recovery(), bm.Trace(), bm.Logger(), bm.Mobile())
  43. outerRouter(engineOut)
  44. if err := engineOut.Start(); err != nil {
  45. log.Error("engineOut.Start error(%v)", err)
  46. panic(err)
  47. }
  48. }
  49. func parseInt(value string) int64 {
  50. intval, err := strconv.ParseInt(value, 10, 64)
  51. if err != nil {
  52. intval = 0
  53. }
  54. return intval
  55. }
  56. func takeBuild(req url.Values) {
  57. buildStr := req.Get("build")
  58. if buildStr != "" {
  59. if tvSvc.TVAppInfo.Build != buildStr {
  60. tvSvc.TVAppInfo.Build = buildStr
  61. }
  62. }
  63. platStr := req.Get("platform")
  64. if platStr != "" {
  65. if tvSvc.TVAppInfo.Platform != platStr {
  66. tvSvc.TVAppInfo.Platform = buildStr
  67. }
  68. }
  69. mobiStr := req.Get("mobi_app")
  70. if mobiStr != "" {
  71. if tvSvc.TVAppInfo.MobiApp != mobiStr {
  72. tvSvc.TVAppInfo.MobiApp = mobiStr
  73. }
  74. }
  75. }
  76. func outerRouter(e *bm.Engine) {
  77. e.Ping(ping)
  78. tv := e.Group("/x/tv", bm.CORS(), bm.CSRF())
  79. e.GET("/x/tv/vip/order/guest_create", authSvc.User, createGuestOrder)
  80. {
  81. app := tv.Group("", authSvc.Guest) // the public group
  82. {
  83. // app pages
  84. app.GET("/homepage", homepage)
  85. app.GET("/zonepage", zonePage)
  86. app.GET("/zone_index", zoneIdx)
  87. app.GET("/media_detail", mediaDetail)
  88. app.GET("/modpage", modpage)
  89. // app functions
  90. app.GET("/upgrade", upgrade)
  91. app.GET("/splash", splash)
  92. app.GET("/recommend", recommend)
  93. app.GET("/suggest", searchSug)
  94. app.GET("/hotword", hotword)
  95. app.GET("/history", history)
  96. // dangbei page
  97. app.GET("/dangbei", dbeiPage)
  98. // video audit status check
  99. app.GET("/loadep", loadEP)
  100. app.GET("/labels", labels)
  101. }
  102. aud := e.Group("/x/tv/audit", bm.CSRF()) // license owner audit related functions
  103. {
  104. aud.POST("", audit)
  105. aud.POST("/transcode", vfySvc.Verify, transcode)
  106. aud.POST("/apply/pgc", vfySvc.Verify, applyPGC)
  107. }
  108. pgc := e.Group("/x/tv/pgc", bm.CSRF(), authSvc.Guest)
  109. {
  110. pgc.GET("/view", mDetailV2)
  111. }
  112. ugc := e.Group("/x/tv/ugc", bm.CSRF(), authSvc.Guest) // the APIs dedicated for ugc
  113. {
  114. ugc.GET("/view", view)
  115. ugc.GET("/load_video", loadVideo)
  116. ugc.GET("/playurl", ugcPlayurl)
  117. }
  118. search := e.Group("/x/tv/search", bm.CSRF(), authSvc.Guest) // the APIs for search
  119. {
  120. search.GET("/types", searchTypes)
  121. search.GET("", searchResult)
  122. wild := search.Group("/wild")
  123. {
  124. wild.GET("", searchAll) // 综合搜索
  125. wild.GET("user", userSearch) // 按用户搜索
  126. wild.GET("pgc", pgcSearch) // pgc番剧影视
  127. }
  128. }
  129. fav := e.Group("/x/tv/favorites", bm.CSRF(), authSvc.Guest)
  130. {
  131. fav.GET("", favorites)
  132. fav.POST("/act", favAct)
  133. }
  134. mango := e.Group("/x/tv/mango", bm.CSRF())
  135. {
  136. mango.GET("/recom", mangoRecom)
  137. }
  138. third := e.Group("/x/tv/third", bm.CSRF())
  139. {
  140. third.GET("/pgc/season", mangoSnPage)
  141. third.GET("/pgc/ep", mangoEpPage)
  142. third.GET("/ugc/archive", mangoArcPage)
  143. third.GET("/ugc/video", mangoVideoPage)
  144. }
  145. idx := e.Group("/x/tv/index", bm.CSRF(), authSvc.Guest)
  146. {
  147. idx.GET("/pgc", pgcIdx)
  148. idx.GET("/ugc", ugcIdx)
  149. }
  150. tv.GET("/region", region) // all region info
  151. vip := e.Group("/x/tv/vip", bm.CSRF())
  152. {
  153. vip.GET("/user/info", authSvc.UserMobile, vipInfo)
  154. vip.GET("/user/yst_info", ystVipInfo)
  155. vip.GET("/panel/user", authSvc.UserMobile, panelInfo)
  156. vip.GET("/panel/guest", authSvc.Guest, guestPanelInfo)
  157. vip.POST("/order/qr", authSvc.UserMobile, createQr)
  158. vip.POST("/order/guest_qr", authSvc.Guest, createGuestQr)
  159. vip.GET("/order/create", authSvc.Guest, createOrder)
  160. vip.GET("/token/info", authSvc.UserMobile, tokenStatus)
  161. vip.POST("/callback/pay", payCallback)
  162. vip.POST("/callback/wx_contract", wxContractCallback)
  163. }
  164. }
  165. }
  166. // ping check db server ok.
  167. func ping(c *bm.Context) {}
  168. func initService(c *conf.Config) {
  169. tvSvc = appsrv.New(c)
  170. viewSvc = viewsrv.New(c)
  171. favSvc = favorite.New(c)
  172. auditSvc = auditsrv.New(c)
  173. gobSvc = gobsrv.New(c)
  174. secSvc = secsrv.New(c)
  175. authSvc = auth.New(c.Auth)
  176. vfySvc = verify.New(c.Verify)
  177. hisSvc = hissrv.New(c)
  178. thirdpSvc = thirdp.New(c)
  179. pgcSvc = pgc.New(c)
  180. tvVipSvc = tvvip.New(c)
  181. }