feat: multi-feature update
This commit is contained in:
@@ -31,6 +31,7 @@ func SetApiRouter(router *gin.Engine) {
|
||||
apiRouter.GET("/about", controller.GetAbout)
|
||||
//apiRouter.GET("/midjourney", controller.GetMidjourney)
|
||||
apiRouter.GET("/home_page_content", controller.GetHomePageContent)
|
||||
apiRouter.GET("/home_stats", controller.GetHomeStats)
|
||||
apiRouter.GET("/pricing", middleware.HeaderNavModuleAuth("pricing"), controller.GetPricing)
|
||||
perfMetricsRoute := apiRouter.Group("/perf-metrics")
|
||||
perfMetricsRoute.Use(middleware.HeaderNavModulePublicOrUserAuth("pricing"))
|
||||
@@ -50,6 +51,11 @@ func SetApiRouter(router *gin.Engine) {
|
||||
apiRouter.POST("/oauth/wechat/bind", middleware.CriticalRateLimit(), anonymousRequestBodyLimit, controller.WeChatBind)
|
||||
apiRouter.GET("/oauth/telegram/login", middleware.CriticalRateLimit(), controller.TelegramLogin)
|
||||
apiRouter.GET("/oauth/telegram/bind", middleware.CriticalRateLimit(), controller.TelegramBind)
|
||||
apiRouter.GET("/hhhl/authorize", middleware.CriticalRateLimit(), controller.HHHLAuthorize)
|
||||
apiRouter.GET("/hhhl/callback", middleware.CriticalRateLimit(), controller.HHHLCallback)
|
||||
apiRouter.POST("/hhhl/token", controller.HHHLToken)
|
||||
apiRouter.GET("/hhhl/token", controller.HHHLToken)
|
||||
apiRouter.GET("/hhhl/userinfo", controller.HHHLUserInfo)
|
||||
// Standard OAuth providers (GitHub, Discord, OIDC, LinuxDO) - unified route
|
||||
apiRouter.GET("/oauth/:provider", middleware.CriticalRateLimit(), controller.HandleOAuth)
|
||||
apiRouter.GET("/ratio_config", middleware.CriticalRateLimit(), controller.GetRatioConfig)
|
||||
|
||||
@@ -18,7 +18,7 @@ func SetRelayRouter(router *gin.Engine) {
|
||||
// https://platform.openai.com/docs/api-reference/introduction
|
||||
modelsRouter := router.Group("/v1/models")
|
||||
modelsRouter.Use(middleware.RouteTag("relay"))
|
||||
modelsRouter.Use(middleware.TokenAuth())
|
||||
modelsRouter.Use(middleware.TokenOrUserAuth())
|
||||
{
|
||||
modelsRouter.GET("", func(c *gin.Context) {
|
||||
switch {
|
||||
@@ -69,7 +69,7 @@ func SetRelayRouter(router *gin.Engine) {
|
||||
relayV1Router := router.Group("/v1")
|
||||
relayV1Router.Use(middleware.RouteTag("relay"))
|
||||
relayV1Router.Use(middleware.SystemPerformanceCheck())
|
||||
relayV1Router.Use(middleware.TokenAuth())
|
||||
relayV1Router.Use(middleware.TokenOrUserAuth())
|
||||
relayV1Router.Use(middleware.ModelRequestRateLimit())
|
||||
{
|
||||
// WebSocket 路由(统一到 Relay)
|
||||
|
||||
+22
-4
@@ -13,12 +13,18 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// ThemeAssets holds the embedded frontend assets for both themes.
|
||||
// ThemeAssets holds the embedded frontend assets for both themes and
|
||||
// the image-gen sub-app.
|
||||
type ThemeAssets struct {
|
||||
DefaultBuildFS embed.FS
|
||||
DefaultIndexPage []byte
|
||||
ClassicBuildFS embed.FS
|
||||
ClassicIndexPage []byte
|
||||
// ImageGen is the image-generation sub-app, served at /image-gen/.
|
||||
// It shares the same origin as the rest of new-api so /api/* and /v1/*
|
||||
// are reachable via the new-api session cookie (no CORS, no sk-key).
|
||||
ImageGenBuildFS embed.FS
|
||||
ImageGenIndexPage []byte
|
||||
}
|
||||
|
||||
func SetWebRouter(router *gin.Engine, assets ThemeAssets) {
|
||||
@@ -26,20 +32,32 @@ func SetWebRouter(router *gin.Engine, assets ThemeAssets) {
|
||||
classicFS := common.EmbedFolder(assets.ClassicBuildFS, "web/classic/dist")
|
||||
themeFS := common.NewThemeAwareFS(defaultFS, classicFS)
|
||||
|
||||
// image-gen sub-app: serve static files under /image-gen, fall back to
|
||||
// its index.html for unknown sub-paths (SPA).
|
||||
imageGenFS := common.EmbedFolder(assets.ImageGenBuildFS, "web/image-gen/dist")
|
||||
|
||||
router.Use(gzip.Gzip(gzip.DefaultCompression))
|
||||
router.Use(middleware.GlobalWebRateLimit())
|
||||
router.Use(middleware.Cache())
|
||||
router.Use(static.Serve("/image-gen", imageGenFS))
|
||||
router.Use(static.Serve("/", themeFS))
|
||||
router.NoRoute(func(c *gin.Context) {
|
||||
c.Set(middleware.RouteTagKey, "web")
|
||||
if strings.HasPrefix(c.Request.RequestURI, "/v1") || strings.HasPrefix(c.Request.RequestURI, "/api") || strings.HasPrefix(c.Request.RequestURI, "/assets") {
|
||||
uri := c.Request.RequestURI
|
||||
// API/relay/static paths are handled by their own routers — 404 cleanly.
|
||||
if strings.HasPrefix(uri, "/v1") || strings.HasPrefix(uri, "/api") || strings.HasPrefix(uri, "/assets") {
|
||||
controller.RelayNotFound(c)
|
||||
return
|
||||
}
|
||||
c.Header("Cache-Control", "no-cache")
|
||||
if common.GetTheme() == "classic" {
|
||||
switch {
|
||||
case strings.HasPrefix(uri, "/image-gen"):
|
||||
// SPA fallback for the image-gen sub-app: any sub-path that didn't
|
||||
// hit a static file gets the image-gen index.html.
|
||||
c.Data(http.StatusOK, "text/html; charset=utf-8", assets.ImageGenIndexPage)
|
||||
case common.GetTheme() == "classic":
|
||||
c.Data(http.StatusOK, "text/html; charset=utf-8", assets.ClassicIndexPage)
|
||||
} else {
|
||||
default:
|
||||
c.Data(http.StatusOK, "text/html; charset=utf-8", assets.DefaultIndexPage)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user