2023-04-22 12:39:27 +00:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-gonic/gin"
|
2023-04-22 13:14:09 +00:00
|
|
|
"one-api/controller"
|
|
|
|
"one-api/middleware"
|
2023-04-22 12:39:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func SetApiRouter(router *gin.Engine) {
|
|
|
|
apiRouter := router.Group("/api")
|
|
|
|
apiRouter.Use(middleware.GlobalAPIRateLimit())
|
|
|
|
{
|
|
|
|
apiRouter.GET("/status", controller.GetStatus)
|
|
|
|
apiRouter.GET("/notice", controller.GetNotice)
|
|
|
|
apiRouter.GET("/about", controller.GetAbout)
|
|
|
|
apiRouter.GET("/verification", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.SendEmailVerification)
|
|
|
|
apiRouter.GET("/reset_password", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.SendPasswordResetEmail)
|
|
|
|
apiRouter.POST("/user/reset", middleware.CriticalRateLimit(), controller.ResetPassword)
|
|
|
|
apiRouter.GET("/oauth/github", middleware.CriticalRateLimit(), controller.GitHubOAuth)
|
|
|
|
apiRouter.GET("/oauth/wechat", middleware.CriticalRateLimit(), controller.WeChatAuth)
|
|
|
|
apiRouter.GET("/oauth/wechat/bind", middleware.CriticalRateLimit(), middleware.UserAuth(), controller.WeChatBind)
|
|
|
|
apiRouter.GET("/oauth/email/bind", middleware.CriticalRateLimit(), middleware.UserAuth(), controller.EmailBind)
|
|
|
|
|
|
|
|
userRoute := apiRouter.Group("/user")
|
|
|
|
{
|
|
|
|
userRoute.POST("/register", middleware.CriticalRateLimit(), middleware.TurnstileCheck(), controller.Register)
|
|
|
|
userRoute.POST("/login", middleware.CriticalRateLimit(), controller.Login)
|
|
|
|
userRoute.GET("/logout", controller.Logout)
|
|
|
|
|
|
|
|
selfRoute := userRoute.Group("/")
|
|
|
|
selfRoute.Use(middleware.UserAuth(), middleware.NoTokenAuth())
|
|
|
|
{
|
|
|
|
selfRoute.GET("/self", controller.GetSelf)
|
|
|
|
selfRoute.PUT("/self", controller.UpdateSelf)
|
|
|
|
selfRoute.DELETE("/self", controller.DeleteSelf)
|
|
|
|
selfRoute.GET("/token", controller.GenerateToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
adminRoute := userRoute.Group("/")
|
|
|
|
adminRoute.Use(middleware.AdminAuth(), middleware.NoTokenAuth())
|
|
|
|
{
|
|
|
|
adminRoute.GET("/", controller.GetAllUsers)
|
|
|
|
adminRoute.GET("/search", controller.SearchUsers)
|
|
|
|
adminRoute.GET("/:id", controller.GetUser)
|
|
|
|
adminRoute.POST("/", controller.CreateUser)
|
|
|
|
adminRoute.POST("/manage", controller.ManageUser)
|
|
|
|
adminRoute.PUT("/", controller.UpdateUser)
|
|
|
|
adminRoute.DELETE("/:id", controller.DeleteUser)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
optionRoute := apiRouter.Group("/option")
|
|
|
|
optionRoute.Use(middleware.RootAuth(), middleware.NoTokenAuth())
|
|
|
|
{
|
|
|
|
optionRoute.GET("/", controller.GetOptions)
|
|
|
|
optionRoute.PUT("/", controller.UpdateOption)
|
|
|
|
}
|
2023-04-22 14:02:59 +00:00
|
|
|
channelRoute := apiRouter.Group("/channel")
|
|
|
|
channelRoute.Use(middleware.AdminAuth())
|
2023-04-22 12:39:27 +00:00
|
|
|
{
|
2023-04-22 14:02:59 +00:00
|
|
|
channelRoute.GET("/", controller.GetAllChannels)
|
|
|
|
channelRoute.GET("/search", controller.SearchChannels)
|
|
|
|
channelRoute.GET("/:id", controller.GetChannel)
|
|
|
|
channelRoute.POST("/", controller.AddChannel)
|
|
|
|
channelRoute.PUT("/", controller.UpdateChannel)
|
|
|
|
channelRoute.DELETE("/:id", controller.DeleteChannel)
|
2023-04-22 12:39:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|