http.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/dm/conf"
  5. "go-common/app/admin/main/dm/service"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/net/http/blademaster/middleware/permit"
  9. "go-common/library/net/http/blademaster/middleware/verify"
  10. )
  11. var (
  12. //dmSvc service
  13. dmSvc *service.Service
  14. verifySvc *verify.Verify
  15. // authSvc auth service
  16. authSvc *permit.Permit
  17. )
  18. // Init http init
  19. func Init(c *conf.Config, s *service.Service) {
  20. dmSvc = s
  21. verifySvc = verify.New(c.Verify)
  22. authSvc = permit.New(c.ManagerAuth)
  23. engine := bm.DefaultServer(c.HTTPServer)
  24. authRouter(engine)
  25. innerRouter(engine)
  26. // init internal server
  27. if err := engine.Start(); err != nil {
  28. log.Error("engine.Start error(%v)", err)
  29. panic(err)
  30. }
  31. }
  32. func authRouter(engine *bm.Engine) {
  33. engine.GET("/monitor/ping", ping)
  34. group := engine.Group("/x/admin/dm")
  35. {
  36. // up filter
  37. group.GET("/upfilter/list", authSvc.Permit("DANMU_POOL_OPERATION"), upFilters)
  38. group.POST("/upfilter/edit", authSvc.Permit("DANMU_POOL_OPERATION"), editUpFilters)
  39. // advance dm list
  40. group.GET("/adv/list", authSvc.Permit("DANMU_POOL_OPERATION"), advList)
  41. // dm transfer
  42. group.GET("/transfer/list", authSvc.Permit("DANMU_POOL_OPERATION"), transferList)
  43. group.POST("/transfer/retry", authSvc.Permit("DANMU_POOL_OPERATION"), reTransferJob)
  44. // dm subject
  45. group.POST("/subject/state/edit", authSvc.Permit("DANMAKU_POOL_SWITCH"), uptSubjectsState)
  46. group.GET("/subject/log", authSvc.Permit("DANMU_LIST"), subjectLog)
  47. group.GET("/subject/archive", authSvc.Permit("DANMU_LIST"), archiveList)
  48. group.POST("/subject/maxlimit", authSvc.Permit("DANMU_POOL_OPERATION"), upSubjectMaxLimit)
  49. // dm mask
  50. group.GET("/mask/state", authSvc.Permit("DANMU_LIST"), maskState)
  51. group.POST("/mask/state/update", authSvc.Permit("DANMAKU_MASK_SWITCH"), updateMaskState)
  52. group.POST("/mask/generate", authSvc.Permit("DANMAKU_MASK_SWITCH"), generateMask)
  53. group.GET("/mask/up", authSvc.Permit("DANMU_LIST"), maskUps)
  54. group.POST("/mask/up/open", authSvc.Permit("DANMAKU_MASK_SWITCH"), maskUpOpen)
  55. // dm task
  56. group.GET("/task/list", authSvc.Permit("DM_TASK_LIST"), taskList)
  57. group.POST("/task/new", authSvc.Permit("DM_TASK_OPERATION"), addTask)
  58. group.POST("/task/review", authSvc.Permit("DM_TASK_REVIEW"), reviewTask)
  59. group.POST("/task/state/edit", authSvc.Permit("DM_TASK_OPERATION"), editTaskState)
  60. group.GET("/task/view", authSvc.Permit("DM_TASK_LIST"), taskView)
  61. group.GET("/task/csv", authSvc.Permit("DM_TASK_LIST"), taskCsv)
  62. // dm list
  63. group.GET("/content/list", authSvc.Permit("DANMU_LIST"), contentList)
  64. group.GET("/report/list/first", authSvc.Permit("DM_REPORT_FIRST_READ"), reportList2)
  65. group.GET("/report/list/second", authSvc.Permit("DM_REPORT_SECOND_READ"), reportList2)
  66. // dm bnj shield
  67. group.POST("/shield/upload", authSvc.Permit("DANMU_LIST"), shieldUpload)
  68. }
  69. subtitleG := group.Group("/subtitle")
  70. {
  71. subtitleG.GET("/list", authSvc.Permit("DM_SUBTITLE"), subtitleList)
  72. subtitleG.POST("/edit", authSvc.Permit("DM_SUBTITLE"), subtitleEdit)
  73. subtitleG.POST("/subject/switch", authSvc.Permit("DM_SUBTITLE"), subtitleSwitch)
  74. }
  75. }
  76. // innerRouter init inner router.
  77. func innerRouter(engine *bm.Engine) {
  78. group := engine.Group("/x/internal/dmadmin", verifySvc.Verify)
  79. {
  80. group.POST("/trans/add", addTrJob)
  81. cg := group.Group("/content")
  82. {
  83. cg.POST("/edit/state", editDMState)
  84. cg.POST("/edit/pool", editDMPool)
  85. cg.POST("/edit/attr", editDMAttr)
  86. cg.GET("/list", dmSearch)
  87. cg.POST("/refresh", xmlCacheFlush)
  88. cg.GET("/index/info", dmIndexInfo)
  89. cg.GET("/log/query", logList)
  90. }
  91. sg := group.Group("/subject")
  92. {
  93. sg.GET("/info", dmIndexInfo)
  94. sg.POST("/fix/count", fixDMCount)
  95. }
  96. rg := group.Group("/report")
  97. {
  98. rg.GET("/list", reportList)
  99. rg.GET("/log", reportLog)
  100. rg.POST("/user/stat/change", changeReportUserStat)
  101. rg.POST("/stat/change", changeReportStat)
  102. rg.POST("/judge", transferJudge)
  103. rg.POST("/judge/result", JudgeResult)
  104. }
  105. mg := group.Group("/monitor")
  106. {
  107. mg.GET("/list", monitorList)
  108. mg.POST("/edit", editMonitor)
  109. }
  110. subtitleG := group.Group("/subtitle")
  111. {
  112. subtitleG.POST("/workflow/callback", subtitleEditCallback)
  113. subtitleG.GET("/workflow/status/list", subtitleStatusList)
  114. subtitleG.GET("/workflow/lans/list", subtitleLanList)
  115. }
  116. }
  117. }
  118. // ping check server state.
  119. func ping(ctx *bm.Context) {
  120. if err := dmSvc.Ping(ctx); err != nil {
  121. log.Error("dm admin ping error(%v)", err)
  122. ctx.JSON(nil, err)
  123. ctx.AbortWithStatus(http.StatusServiceUnavailable)
  124. }
  125. ctx.Next()
  126. }