Files
mce/internal/router/frontend.go
Victor_Jay 680df7371a feat: 实现关注系统 + 通知侧边栏分类 TAB + 点赞聚合通知
- 新增关注系统:UserFollow 模型、FollowService(toggle/status/列表隐私控制)
- User 新增 FollowersCount/FollowingCount/FollowListPublic/NotifyPrefs 字段
- Space 页面增加四态关注按钮(关注/已关注/回关/已互粉)+ 粉丝/关注数链接
- 新增 /space/:uid/followers 和 /space/:uid/following 列表页
- 新增 NotifyFollow/NotifyLikeAggregated 通知类型
- ReactionService 点赞时写入 daily_like_summary,访问时生成聚合通知
- FollowService 关注时触发 NotifyFollow 通知
- 消息中心侧边栏升级为分类 TAB(全部/系统通知/@艾特/点赞/关注)
- NotificationService 新增 ListByCategory 按分类分页查询
2026-06-01 16:30:46 +08:00

84 lines
2.4 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) {
posts, total, err := d.postService.List("", 1, 6)
if err != nil {
posts = nil
total = 0
}
c.HTML(http.StatusOK, "home/index.html", common.BuildPageData(c, gin.H{
"Title": "首页",
"ExtraCSS": "/static/css/home.css",
"Posts": posts,
"PostCount": total,
}))
})
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("/space/:uid/followers", d.followPageCtrl.FollowersPage)
pages.GET("/space/:uid/following", d.followPageCtrl.FollowingPage)
// 帖子页面
pages.GET("/posts", d.postCtrl.ListPage)
pages.GET("/posts/:id", d.postCtrl.ShowPage)
pages.GET("/posts/:id/edit", d.authMdw.Required(), func(c *gin.Context) {
c.Redirect(http.StatusMovedPermanently, "/studio/write?id="+c.Param("id"))
})
// 创作中心(需登录)
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)
}
}