middleware: - 拆分 auth.go → auth.go + auth_token.go + auth_parser.go + auth_admin.go - 拆分 csrf.go → csrf.go + csrf_token.go - 拆分 ratelimit.go → ratelimit.go + ratelimit_core.go + ratelimit_cleanup.go - 修复 import 未使用/缺失问题 router: - 拆分 router.go → admin.go + api.go + frontend.go + deps_core.go + deps_extra.go feat(admin): 站点设置管理页面 - 新增 SSR 页面 /admin/site-settings(仅 Owner) - 审核开关 Toggle 即时保存 - 通用设置展示 - 侧边栏新增站点设置入口 - 注册 UpdateBoolSetting/GetBoolSetting API 路由
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package router
|
||
|
||
import (
|
||
"net/http"
|
||
|
||
"metazone.cc/metalab/internal/common"
|
||
"metazone.cc/metalab/internal/config"
|
||
"metazone.cc/metalab/internal/middleware"
|
||
|
||
"github.com/gin-gonic/gin"
|
||
)
|
||
|
||
// setupFrontendRoutes 注册前端页面路由
|
||
func setupFrontendRoutes(r *gin.Engine, cfg *config.Config, d *dependencies) {
|
||
// --- 页面路由(CSRF 仅下发 token,不验证) ---
|
||
pages := r.Group("/")
|
||
pages.Use(d.authMdw.Optional())
|
||
pages.Use(middleware.CSRF(cfg))
|
||
pages.Use(func(c *gin.Context) {
|
||
middleware.SetCSRFToken(c, cfg)
|
||
c.Next()
|
||
})
|
||
{
|
||
pages.GET("/", func(c *gin.Context) {
|
||
c.HTML(http.StatusOK, "home/index.html", common.BuildPageData(c, gin.H{
|
||
"Title": "首页",
|
||
"ExtraCSS": "/static/css/home.css",
|
||
}))
|
||
})
|
||
|
||
pages.GET("/settings", func(c *gin.Context) {
|
||
c.Redirect(http.StatusFound, "/settings/profile")
|
||
})
|
||
pages.GET("/settings/:tab", d.settingsCtrl.SettingsPage)
|
||
pages.GET("/messages", d.messageCtrl.MessagesPage)
|
||
}
|
||
|
||
// 认证页面(已登录自动跳走)
|
||
authPages := r.Group("/auth")
|
||
authPages.Use(d.authMdw.Optional())
|
||
authPages.Use(middleware.CSRF(cfg))
|
||
authPages.Use(func(c *gin.Context) {
|
||
middleware.SetCSRFToken(c, cfg)
|
||
c.Next()
|
||
})
|
||
{
|
||
authPages.GET("/register", d.authCtrl.RegisterPage)
|
||
authPages.GET("/login", d.authCtrl.LoginPage)
|
||
}
|
||
}
|