api-router.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package router
  2. import (
  3. "one-api/controller"
  4. "one-api/middleware"
  5. "github.com/gin-contrib/gzip"
  6. "github.com/gin-gonic/gin"
  7. )
  8. func SetApiRouter(router *gin.Engine) {
  9. apiRouter := router.Group("/api")
  10. apiRouter.Use(gzip.Gzip(gzip.DefaultCompression))
  11. apiRouter.Use(middleware.GlobalAPIRateLimit())
  12. {
  13. apiRouter.GET("/status", controller.GetStatus)
  14. apiRouter.GET("/status/test", middleware.AdminAuth(), controller.TestStatus)
  15. apiRouter.GET("/notice", controller.GetNotice)
  16. apiRouter.GET("/about", controller.GetAbout)
  17. //apiRouter.GET("/midjourney", controller.GetMidjourney)
  18. apiRouter.GET("/home_page_content", controller.GetHomePageContent)
  19. apiRouter.GET("/verification", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.SendEmailVerification)
  20. apiRouter.GET("/reset_password", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.SendPasswordResetEmail)
  21. apiRouter.POST("/user/reset", middleware.CriticalRateLimit(), controller.ResetPassword)
  22. apiRouter.GET("/oauth/github", middleware.CriticalRateLimit(), controller.GitHubOAuth)
  23. apiRouter.GET("/oauth/state", middleware.CriticalRateLimit(), controller.GenerateOAuthCode)
  24. apiRouter.GET("/oauth/wechat", middleware.CriticalRateLimit(), controller.WeChatAuth)
  25. apiRouter.GET("/oauth/wechat/bind", middleware.CriticalRateLimit(), middleware.UserAuth(), controller.WeChatBind)
  26. apiRouter.GET("/oauth/email/bind", middleware.CriticalRateLimit(), middleware.UserAuth(), controller.EmailBind)
  27. apiRouter.GET("/oauth/telegram/login", middleware.CriticalRateLimit(), controller.TelegramLogin)
  28. apiRouter.GET("/oauth/telegram/bind", middleware.CriticalRateLimit(), middleware.UserAuth(), controller.TelegramBind)
  29. userRoute := apiRouter.Group("/user")
  30. {
  31. userRoute.POST("/register", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.Register)
  32. userRoute.POST("/login", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.Login)
  33. //userRoute.POST("/tokenlog", middleware.CriticalRateLimit(), controller.TokenLog)
  34. userRoute.GET("/logout", controller.Logout)
  35. userRoute.GET("/epay/notify", controller.EpayNotify)
  36. selfRoute := userRoute.Group("/")
  37. selfRoute.Use(middleware.UserAuth())
  38. {
  39. selfRoute.GET("/self", controller.GetSelf)
  40. selfRoute.GET("/models", controller.GetUserModels)
  41. selfRoute.PUT("/self", controller.UpdateSelf)
  42. selfRoute.DELETE("/self", controller.DeleteSelf)
  43. selfRoute.GET("/token", controller.GenerateAccessToken)
  44. selfRoute.GET("/aff", controller.GetAffCode)
  45. selfRoute.POST("/topup", controller.TopUp)
  46. selfRoute.POST("/pay", controller.RequestEpay)
  47. selfRoute.POST("/amount", controller.RequestAmount)
  48. selfRoute.POST("/aff_transfer", controller.TransferAffQuota)
  49. }
  50. adminRoute := userRoute.Group("/")
  51. adminRoute.Use(middleware.AdminAuth())
  52. {
  53. adminRoute.GET("/", controller.GetAllUsers)
  54. adminRoute.GET("/search", controller.SearchUsers)
  55. adminRoute.GET("/:id", controller.GetUser)
  56. adminRoute.POST("/", controller.CreateUser)
  57. adminRoute.POST("/manage", controller.ManageUser)
  58. adminRoute.PUT("/", controller.UpdateUser)
  59. adminRoute.DELETE("/:id", controller.DeleteUser)
  60. }
  61. }
  62. optionRoute := apiRouter.Group("/option")
  63. optionRoute.Use(middleware.RootAuth())
  64. {
  65. optionRoute.GET("/", controller.GetOptions)
  66. optionRoute.PUT("/", controller.UpdateOption)
  67. }
  68. channelRoute := apiRouter.Group("/channel")
  69. channelRoute.Use(middleware.AdminAuth())
  70. {
  71. channelRoute.GET("/", controller.GetAllChannels)
  72. channelRoute.GET("/search", controller.SearchChannels)
  73. channelRoute.GET("/models", controller.ChannelListModels)
  74. channelRoute.GET("/:id", controller.GetChannel)
  75. channelRoute.GET("/test", controller.TestAllChannels)
  76. channelRoute.GET("/test/:id", controller.TestChannel)
  77. channelRoute.GET("/update_balance", controller.UpdateAllChannelsBalance)
  78. channelRoute.GET("/update_balance/:id", controller.UpdateChannelBalance)
  79. channelRoute.POST("/", controller.AddChannel)
  80. channelRoute.PUT("/", controller.UpdateChannel)
  81. channelRoute.DELETE("/disabled", controller.DeleteDisabledChannel)
  82. channelRoute.DELETE("/:id", controller.DeleteChannel)
  83. channelRoute.POST("/batch", controller.DeleteChannelBatch)
  84. channelRoute.POST("/fix", controller.FixChannelsAbilities)
  85. }
  86. tokenRoute := apiRouter.Group("/token")
  87. tokenRoute.Use(middleware.UserAuth())
  88. {
  89. tokenRoute.GET("/", controller.GetAllTokens)
  90. tokenRoute.GET("/search", controller.SearchTokens)
  91. tokenRoute.GET("/:id", controller.GetToken)
  92. tokenRoute.POST("/", controller.AddToken)
  93. tokenRoute.PUT("/", controller.UpdateToken)
  94. tokenRoute.DELETE("/:id", controller.DeleteToken)
  95. }
  96. redemptionRoute := apiRouter.Group("/redemption")
  97. redemptionRoute.Use(middleware.AdminAuth())
  98. {
  99. redemptionRoute.GET("/", controller.GetAllRedemptions)
  100. redemptionRoute.GET("/search", controller.SearchRedemptions)
  101. redemptionRoute.GET("/:id", controller.GetRedemption)
  102. redemptionRoute.POST("/", controller.AddRedemption)
  103. redemptionRoute.PUT("/", controller.UpdateRedemption)
  104. redemptionRoute.DELETE("/:id", controller.DeleteRedemption)
  105. }
  106. logRoute := apiRouter.Group("/log")
  107. logRoute.GET("/", middleware.AdminAuth(), controller.GetAllLogs)
  108. logRoute.DELETE("/", middleware.AdminAuth(), controller.DeleteHistoryLogs)
  109. logRoute.GET("/stat", middleware.AdminAuth(), controller.GetLogsStat)
  110. logRoute.GET("/self/stat", middleware.UserAuth(), controller.GetLogsSelfStat)
  111. logRoute.GET("/search", middleware.AdminAuth(), controller.SearchAllLogs)
  112. logRoute.GET("/self", middleware.UserAuth(), controller.GetUserLogs)
  113. logRoute.GET("/self/search", middleware.UserAuth(), controller.SearchUserLogs)
  114. dataRoute := apiRouter.Group("/data")
  115. dataRoute.GET("/", middleware.AdminAuth(), controller.GetAllQuotaDates)
  116. dataRoute.GET("/self", middleware.UserAuth(), controller.GetUserQuotaDates)
  117. logRoute.Use(middleware.CORS())
  118. {
  119. logRoute.GET("/token", controller.GetLogByKey)
  120. }
  121. groupRoute := apiRouter.Group("/group")
  122. groupRoute.Use(middleware.AdminAuth())
  123. {
  124. groupRoute.GET("/", controller.GetGroups)
  125. }
  126. mjRoute := apiRouter.Group("/mj")
  127. mjRoute.GET("/self", middleware.UserAuth(), controller.GetUserMidjourney)
  128. mjRoute.GET("/", middleware.AdminAuth(), controller.GetAllMidjourney)
  129. }
  130. }