http.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. package http
  2. import (
  3. "net/http"
  4. "strconv"
  5. "go-common/app/admin/main/tv/conf"
  6. "go-common/app/admin/main/tv/service"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/net/http/blademaster/middleware/permit"
  10. "go-common/library/net/http/blademaster/middleware/verify"
  11. "go-common/library/net/http/blademaster/render"
  12. )
  13. var (
  14. tvSrv *service.Service
  15. vfySvc *verify.Verify
  16. authSvc *permit.Permit
  17. )
  18. const (
  19. _errIDNotFound = "ids not found"
  20. _errTitleExist = "Title exists already"
  21. )
  22. // Init init http sever instance.
  23. func Init(c *conf.Config, s *service.Service) {
  24. initService(c, s)
  25. engine := bm.DefaultServer(c.HTTPServer)
  26. innerRouter(engine)
  27. // init internal server
  28. if err := engine.Start(); err != nil {
  29. log.Error("engine.Start error(%v)", err)
  30. panic(err)
  31. }
  32. }
  33. // initService init service
  34. func initService(c *conf.Config, s *service.Service) {
  35. tvSrv = s
  36. vfySvc = verify.New(nil)
  37. authSvc = permit.New(c.Auth)
  38. }
  39. func parseInt(value string) int64 {
  40. intval, err := strconv.ParseInt(value, 10, 64)
  41. if err != nil {
  42. intval = 0
  43. }
  44. return intval
  45. }
  46. func atoi(value string) (intval int) {
  47. intval, err := strconv.Atoi(value)
  48. if err != nil {
  49. intval = 0
  50. }
  51. return intval
  52. }
  53. // innerRouter
  54. func innerRouter(e *bm.Engine) {
  55. // ping monitor
  56. e.GET("/monitor/ping", ping)
  57. // internal api
  58. bg := e.Group("/x/admin/tv")
  59. {
  60. // cms content edit
  61. cont := bg.Group("/cont", vfySvc.Verify)
  62. {
  63. cont.POST("/online", online)
  64. cont.POST("/hidden", hidden)
  65. }
  66. // pgc ep inject
  67. epIn := bg.Group("/ep", vfySvc.Verify)
  68. {
  69. epIn.POST("/create", createEP)
  70. epIn.POST("/remove", removeEP)
  71. }
  72. // pgc season inject
  73. snIn := bg.Group("/season", vfySvc.Verify)
  74. {
  75. snIn.POST("/create", createSeason)
  76. snIn.POST("/remove", removeSeason)
  77. }
  78. // intervsRank edit
  79. interv := bg.Group("/intervs", vfySvc.Verify)
  80. {
  81. rank := interv.Group("/rank")
  82. {
  83. rank.GET("/list", intervsRank)
  84. rank.POST("/publish", rankPub)
  85. }
  86. module := interv.Group("/module")
  87. {
  88. module.GET("/list", intervsMod)
  89. module.POST("/publish", modPub)
  90. }
  91. index := interv.Group("/index")
  92. {
  93. index.GET("/list", intervsIndex)
  94. index.POST("/publish", indexPub)
  95. }
  96. }
  97. // audit result
  98. audit := bg.Group("/audit_result")
  99. {
  100. aud := audit.Group("")
  101. {
  102. aud.GET("/ep", epResult)
  103. aud.GET("/season", seasonResult)
  104. aud.GET("/archive", arcResult)
  105. aud.GET("/video", videoResult)
  106. aud.GET("/ugctypes", auditCategory)
  107. audit.GET("/abnor_export", abnorExport)
  108. audit.GET("/abnor_debug", abnorDebug)
  109. }
  110. audit.POST("/unshelve", authSvc.Permit("TV_MEDIA_DEL"), unShelve)
  111. }
  112. // content repository
  113. crepo := bg.Group("/contrepo", vfySvc.Verify)
  114. {
  115. crepo.GET("/list", contList)
  116. crepo.GET("/info", contInfo)
  117. crepo.POST("/save", saveCont)
  118. crepo.GET("/preview", preview)
  119. crepo.POST("/online", contOnline)
  120. crepo.POST("/hidden", contHidden)
  121. crepo.POST("/upload", upbfs)
  122. }
  123. // season repo
  124. srepo := bg.Group("/searepo", vfySvc.Verify)
  125. {
  126. srepo.GET("/list", seasonList)
  127. srepo.GET("/info", seasonInfo)
  128. srepo.POST("/save", saveSeason)
  129. srepo.POST("/online", seasonOnline)
  130. srepo.POST("/hidden", seasonHidden)
  131. // ugc
  132. crugc := srepo.Group("/ugc")
  133. {
  134. //archive
  135. crugc.GET("/archive/lists", arcList)
  136. crugc.GET("/archive/category", arcCategory)
  137. crugc.POST("/archive/online", arcOnline)
  138. crugc.POST("/archive/hidden", arcHidden)
  139. crugc.GET("/archive/arcTypeRPC", arcTypeRPC)
  140. crugc.POST("/archive/update", arcUpdate)
  141. //video
  142. crugc.GET("/video/lists", VideoList)
  143. crugc.POST("/video/online", VideoOnline)
  144. crugc.POST("/video/hidden", VideoHidden)
  145. crugc.GET("/video/preview", VideoPreview)
  146. crugc.POST("/video/update", videoUpdate)
  147. }
  148. }
  149. // version mgt
  150. ver := bg.Group("/version", vfySvc.Verify)
  151. {
  152. ver.GET("/list", versionList)
  153. ver.GET("/info", versionInfo)
  154. ver.POST("/save", saveVersion)
  155. ver.POST("/add", addVersion)
  156. ver.POST("/delete", versionDel)
  157. }
  158. // version update mgt
  159. verup := bg.Group("/verupdate", vfySvc.Verify)
  160. {
  161. verup.GET("/list", verUpdateList)
  162. verup.POST("/add", addVerUpdate)
  163. verup.POST("/save", saveVerUpdate)
  164. verup.POST("/enable", verUpdateEnable)
  165. verup.GET("/full", fullPackageImport)
  166. }
  167. // channel mgt
  168. chl := bg.Group("/channel", vfySvc.Verify)
  169. {
  170. chl.GET("/list", chlList)
  171. chl.GET("/info", chlInfo)
  172. chl.POST("/edit", chlEdit)
  173. chl.POST("/add", chlAdd)
  174. chl.POST("/delete", chlDel)
  175. }
  176. upper := bg.Group("/upper", authSvc.Permit("TV_AUDIT_MGT"))
  177. {
  178. upper.POST("/add", upAdd)
  179. upper.POST("/import", upImport)
  180. upper.POST("/del", upDel)
  181. upper.GET("", upList)
  182. }
  183. upCMS := bg.Group("upcms", vfySvc.Verify)
  184. {
  185. upCMS.GET("/list", upcmsList)
  186. upCMS.POST("/audit", upcmsAudit)
  187. upCMS.POST("/edit", upcmsEdit)
  188. }
  189. //search intervene
  190. si := bg.Group("/searchInter", vfySvc.Verify)
  191. {
  192. si.GET("/list", searInterList)
  193. si.POST("/add", searInterAdd)
  194. si.POST("/edit", searInterEdit)
  195. si.POST("/delete", searInterDel)
  196. si.POST("/rank", searInterRank)
  197. si.POST("/publish", searInterPublish)
  198. si.POST("/publishList", searInterPubList)
  199. }
  200. bg.POST("/archive/add", authSvc.Permit("TV_AUDIT_MGT"), arcAdd)
  201. //modules manager
  202. mod := bg.Group("/modules", vfySvc.Verify)
  203. {
  204. mod.POST("/add", modulesAdd)
  205. mod.GET("/list", modulesList)
  206. mod.GET("/editGet", modulesEditGet)
  207. mod.POST("/editPost", modulesEditPost)
  208. mod.POST("/publish", modulesPublish)
  209. mod.GET("/sup_cat", supCat)
  210. }
  211. //watermark
  212. wr := bg.Group("/watermark", authSvc.Permit("TV_AUDIT_MGT"))
  213. {
  214. wr.GET("/list", waterMarklist)
  215. wr.POST("/add", waterMarkAdd)
  216. wr.POST("/delete", waterMarkDelete)
  217. }
  218. mango := bg.Group("/mango", authSvc.Permit("TV_AUDIT_MGT"))
  219. {
  220. mango.GET("/list", mangoList)
  221. mango.POST("/add", mangoAdd)
  222. mango.POST("/edit", mangoEdit)
  223. mango.POST("/delete", mangoDel)
  224. mango.POST("/publish", mangoPub)
  225. }
  226. trans := bg.Group("/trans", authSvc.Permit("TV_AUDIT_MGT"))
  227. {
  228. trans.GET("/list", transList)
  229. }
  230. label := bg.Group("/label", vfySvc.Verify)
  231. {
  232. label.POST("/act", actLabels)
  233. label.POST("/edit", editLabel)
  234. label.POST("/publish", pubLabel)
  235. ugcLabel := label.Group("/ugc")
  236. {
  237. ugcLabel.POST("/add_time", addTime)
  238. ugcLabel.POST("/edit_time", editTime)
  239. ugcLabel.POST("/del_time", delTmLabels)
  240. ugcLabel.GET("/list", ugcLabels)
  241. }
  242. pgcLabel := label.Group("/pgc")
  243. {
  244. pgcLabel.GET("/list", pgcLabels)
  245. pgcLabel.GET("/types", pgcLblTps)
  246. }
  247. }
  248. // app manager
  249. app := bg.Group("/app", vfySvc.Verify)
  250. {
  251. // region manager
  252. reg := app.Group("/region")
  253. {
  254. reg.GET("/list", reglist)
  255. reg.POST("/sort", regSort)
  256. reg.POST("/save", saveReg)
  257. reg.POST("/publish", upState)
  258. }
  259. }
  260. // vip tv-vip
  261. vip := bg.Group("/vip", authSvc.Permit("TV_VIP"))
  262. {
  263. // user info
  264. vip.GET("/user/info", userInfo)
  265. //order info
  266. vip.GET("/order/list", orderList)
  267. //panel info
  268. panel := vip.Group("/panel")
  269. {
  270. panel.GET("/info", panelInfo)
  271. panel.POST("/status", panelStatus)
  272. panel.POST("/save", savePanel)
  273. panel.GET("/list", panelList)
  274. }
  275. }
  276. }
  277. }
  278. // ping check server ok.
  279. func ping(c *bm.Context) {
  280. }
  281. func renderErrMsg(c *bm.Context, code int, msg string) {
  282. data := map[string]interface{}{
  283. "code": code,
  284. "message": msg,
  285. }
  286. c.Render(http.StatusOK, render.MapJSON(data))
  287. }