http.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/app/admin/main/reply/conf"
  5. "go-common/app/admin/main/reply/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. rpSvc *service.Service
  13. verifySvc *verify.Verify
  14. )
  15. // Init init http.
  16. func Init(c *conf.Config) {
  17. // init services
  18. rpSvc = service.New(c)
  19. verifySvc = verify.New(c.Verify)
  20. auther := permit.New(c.ManagerAuth)
  21. engine := bm.DefaultServer(c.HTTPServer)
  22. authRouter(engine, auther)
  23. interRouter(engine)
  24. verifyRouter(engine)
  25. // serve port
  26. if err := engine.Start(); err != nil {
  27. log.Error("engine.Start error(%v)", err)
  28. panic(err)
  29. }
  30. }
  31. type managerAuther interface {
  32. Permit(permit string) bm.HandlerFunc
  33. }
  34. type fakeAuth struct {
  35. }
  36. func (a *fakeAuth) Permit(permit string) bm.HandlerFunc {
  37. return func(ctx *bm.Context) {
  38. ctx.Next()
  39. }
  40. }
  41. func authRouter(engine *bm.Engine, auther managerAuther) {
  42. engine.GET("/monitor/ping", ping)
  43. group := engine.Group("/x/admin/reply")
  44. {
  45. // reply
  46. group.GET("/search", auther.Permit("REPLY_READONLY"), replySearch) // 评论列表
  47. group.GET("/export", auther.Permit("REPLY_READONLY"), replyExport) // 评论列表
  48. group.POST("/pass", auther.Permit("REPLY_MGR"), adminPassReply) // 通过评论
  49. group.POST("/recover", auther.Permit("REPLY_MGR"), adminRecoverReply) // 恢复评论
  50. group.POST("/edit", auther.Permit("REPLY_MGR"), adminEditReply) // 编辑评论
  51. group.POST("/del", auther.Permit("REPLY_MGR"), adminDelReply) // 删除评论
  52. group.POST("/top", auther.Permit("REPLY_TOP_MGR"), adminTopReply) // 置顶评论
  53. group.GET("/top/log", auther.Permit("REPLY_TOP_MGR"), adminTopReplyLog) // 置顶评论日志搜索
  54. group.GET("/reply/top", auther.Permit("REPLY_MGR"), topChildReply)
  55. // report
  56. group.GET("/report/search", auther.Permit("REPLY_REPORT_READONLY"), reportSearch) // 举报列表
  57. group.POST("/report/del", auther.Permit("REPLY_MGR"), reportDel) // 举报删除
  58. group.POST("/report/ignore", auther.Permit("REPLY_MGR"), reportIgnore) // 举报忽略
  59. group.POST("/report/recover", auther.Permit("REPLY_MGR"), reportRecover) // 举报恢复
  60. group.POST("/report/transfer", auther.Permit("REPLY_MGR"), reportTransfer) // 举报转审
  61. group.POST("/report/state", auther.Permit("REPLY_MGR"), reportStateSet) // 设置举报状态
  62. // monitor
  63. group.GET("/monitor/search", auther.Permit("REPLY_MONITOR_READONLY"), monitorSearch) // 监控列表
  64. group.GET("/monitor/stats", auther.Permit("REPLY_MONITOR_READONLY"), monitorStats) // 监控统计
  65. group.POST("/monitor/state", auther.Permit("REPLY_MONITOR_MGR"), monitorState) // 监控状态
  66. group.GET("/mointor/log", auther.Permit("REPLY_MONITOR_READONLY"), monitorLog) // 监控操作日志
  67. // config
  68. group.POST("/config/update", auther.Permit("REPLY_MGR"), updateReplyConfig) // 配置更新
  69. group.POST("/config/renew", auther.Permit("REPLY_MGR"), renewReplyConfig) // 配置添加
  70. group.GET("/config/info", auther.Permit("REPLY_READONLY"), loadReplyConfig) // 配置信息
  71. group.GET("/config/list", auther.Permit("REPLY_READONLY"), paginateReplyConfig) // 配置列表
  72. // notice
  73. group.GET("/notice/detail", auther.Permit("MANAGER_NOTICE"), getNotice) // 通知信息
  74. group.GET("/notice/list", auther.Permit("MANAGER_NOTICE"), listNotice2) // 通知列表
  75. group.POST("/notice/edit", auther.Permit("MANAGER_NOTICE"), editNotice) // 通知编辑
  76. group.POST("/notice/delete", auther.Permit("MANAGER_NOTICE"), deleteNotice) // 通知删除
  77. group.POST("/notice/offline", auther.Permit("MANAGER_NOTICE"), offlineNotice) // 下线通知
  78. group.POST("/notice/online", auther.Permit("MANAGER_NOTICE"), onlineNotice) // 上线通知
  79. // subject
  80. group.GET("/subject/info", auther.Permit("REPLY_READONLY"), adminSubject) // 主题信息
  81. group.POST("/subject/state", auther.Permit("REPLY_SUBJECT_FREEZE"), adminSubjectState) // 主题状态设置
  82. group.POST("/subject/freeze", auther.Permit("REPLY_SUBJECT_FREEZE"), SubFreeze) // 主题冻结或解冻评论
  83. group.GET("/subject/log", auther.Permit("REPLY_READONLY"), SubLogSearch) // 主题操作日志搜索
  84. // action
  85. group.GET("/action/count", auther.Permit("REPLY_MGR"), actionCount)
  86. group.POST("/action/update", auther.Permit("REPLY_MGR"), actionUpdate)
  87. // log
  88. group.GET("/log", auther.Permit("REPLY_MGR"), logByRpID)
  89. // emoji
  90. group.GET("/emoji/list", auther.Permit("REPLY_EMOJI"), listEmoji)
  91. group.POST("/emoji/add", auther.Permit("REPLY_EMOJI"), createEmoji)
  92. group.POST("/emoji/state", auther.Permit("REPLY_EMOJI"), upEmojiState)
  93. group.POST("/emoji/sort", auther.Permit("REPLY_EMOJI"), upEmojiSort)
  94. group.POST("/emoji/edit", auther.Permit("REPLY_EMOJI"), upEmoji)
  95. group.GET("/emoji/package/list", auther.Permit("REPLY_EMOJI"), listEmojiPacks)
  96. group.POST("/emoji/package/add", auther.Permit("REPLY_EMOJI"), createEmojiPackage)
  97. group.POST("/emoji/package/edit", auther.Permit("REPLY_EMOJI"), editEmojiPack)
  98. group.POST("/emoji/package/sort", auther.Permit("REPLY_EMOJI"), upEmojiPackageSort)
  99. // business
  100. group.GET("/business/list", listBusiness)
  101. group.GET("/business/get", getBusiness)
  102. group.POST("/business/add", addBusiness)
  103. group.POST("/business/update", upBusiness)
  104. group.POST("/business/state", upBusiState)
  105. // fold reply
  106. group.POST("/fold", foldReply)
  107. }
  108. }
  109. func interRouter(engine *bm.Engine) {
  110. group := engine.Group("/x/internal/replyadmin", verifySvc.Verify)
  111. {
  112. //log
  113. group.GET("/log", logByRpID)
  114. //search
  115. group.GET("/reply/search", replySearch)
  116. group.GET("/report/search", reportSearch)
  117. // moniter
  118. group.GET("/monitor/stats", monitorStats)
  119. group.GET("/monitor/search", monitorSearch)
  120. group.POST("/monitor/state", monitorState)
  121. // config
  122. group.POST("/config/update", updateReplyConfig)
  123. group.POST("/config/rewnew", renewReplyConfig)
  124. group.GET("/config/info", loadReplyConfig)
  125. group.GET("/config/list", paginateReplyConfig)
  126. // notice
  127. group.GET("/notice/detail", getNotice)
  128. group.GET("/notice/list", listNotice)
  129. group.POST("/notice/edit", editNotice)
  130. group.POST("/notice/delete", deleteNotice)
  131. group.POST("/notice/offline", offlineNotice)
  132. group.POST("/notice/online", onlineNotice)
  133. }
  134. }
  135. func verifyRouter(engine *bm.Engine) {
  136. group := engine.Group("/x/admin/reply/internal")
  137. {
  138. group.POST("/spam", verifySvc.Verify, adminMarkAsSpam) // 标记评论为垃圾
  139. group.POST("/del", verifySvc.Verify, adminDelReply) // 删除评论
  140. group.POST("/callback/del", verifySvc.Verify, callbackDelReply) // 回调删除评论
  141. group.GET("/reply", adminReplyList) // 获得评论列表接口
  142. }
  143. }
  144. func ping(ctx *bm.Context) {
  145. if err := rpSvc.Ping(ctx); err != nil {
  146. log.Error("reply admin ping error(%v)", err)
  147. ctx.JSON(nil, err)
  148. ctx.AbortWithStatus(http.StatusServiceUnavailable)
  149. }
  150. }