api-router.go 6.2 KB

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