This repository has been archived on 2026-06-21. You can view files and clone it, but cannot push or open issues or pull requests.
Files
MetaLab/internal/router/frontend.go
Victor_Jay 7659aee468 feat: 新增创作中心(/studio),支持数据概览、内容管理、草稿箱、写文章
- 新增 StudioController,依赖 studioUseCase 接口,遵循 ISP 接口隔离
- PostRepo 新增 FindByUserIDAndStatus 方法,按用户+状态分页查询
- PostService 新增 ListByUser、GetOverview 及 StudioOverview 统计
- /studio 页面路由(概览/管理/草稿箱/写文章/数据分析)+ /api/studio API
- 复用 Vditor 编辑器,studio-editor.js 对接 /api/studio/posts 端点
- 新增 studio.css(B站风格三栏布局+统计卡片+状态筛选tabs)
- 模板引擎注册 add/subtract 函数,分页模板中直接使用
2026-05-30 19:55:29 +08:00

72 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
// 用户空间(静态 /space 必须在 :uid 之前注册)
pages.GET("/space", d.spaceCtrl.MySpace)
pages.GET("/space/:uid", d.spaceCtrl.ShowSpace)
// 帖子页面
pages.GET("/posts", d.postCtrl.ListPage)
pages.GET("/posts/new", d.authMdw.Required(), d.postCtrl.NewPage)
pages.GET("/posts/:id", d.postCtrl.ShowPage)
pages.GET("/posts/:id/edit", d.authMdw.Required(), d.postCtrl.EditPage)
// 创作中心(需登录)
studioPages := pages.Group("/studio")
studioPages.Use(d.authMdw.Required())
{
studioPages.GET("", d.studioCtrl.OverviewPage)
studioPages.GET("/posts", d.studioCtrl.PostsPage)
studioPages.GET("/drafts", d.studioCtrl.DraftsPage)
studioPages.GET("/write", d.studioCtrl.WritePage)
studioPages.GET("/analytics", d.studioCtrl.AnalyticsPage)
}
}
// 认证页面(已登录自动跳走)
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)
}
}