This commit is contained in:
toom1996
2026-08-30 10:45:34 +08:00
parent a6724265ad
commit 9c3403a903
23 changed files with 284 additions and 508 deletions

View File

@ -14,13 +14,14 @@ import (
// Options 路由注册所需的全部依赖,由 main 装配后传入。
type Options struct {
Config *config.Config
JWT *jwt.Manager
Article *handler.ArticleHandler
Brand *handler.BrandHandler
Auth *handler.AuthHandler
Health *handler.HealthHandler
SSG *handler.SSGHandler
Config *config.Config
JWT *jwt.Manager
Article *handler.ArticleHandler
Brand *handler.BrandHandler
StreetSnap *handler.StreetSnapHandler
Auth *handler.AuthHandler
Health *handler.HealthHandler
SSG *handler.SSGHandler
}
// New 构建 Gin 引擎并注册全部对外路由。
@ -43,18 +44,31 @@ func New(opt Options) *gin.Engine {
// 对外公开接口:只读查询,不暴露任何后台管理字段
public := api.Group("/public")
// ClientSign 仅挂在「列表 / 品牌」两个批量查询接口上:
// 这俩是爬虫批量 dump 的主要目标,要求前端 JS 签名可抬高抓取成本。
public.Use(middleware.ClientSign(opt.Config.ClientSign))
{
public.GET("/articles", opt.Article.List)
public.GET("/articles/:id", opt.Article.Detail)
// 走秀档案列表(按品牌过滤走 ?brand_id 查询参数)
public.GET("/runway-looks", opt.Article.List)
// 品牌列表(A-Z 索引 / 搜索)
public.GET("/brands", opt.Brand.List)
// 街拍列表(批量接口,受 ClientSign 保护,与 runway-looks/brands 同批)
public.GET("/street-snaps", opt.StreetSnap.List)
}
// 走秀详情:被 SSR 服务端按需渲染(getSsrArticle)直接 fetch 调用,属可信内部取数,
// 不走前端 JS 签名,单独挂载以免破坏服务端渲染。单篇枚举防护由 HashID 承担。
api.GET("/public/runway-looks/:id", opt.Article.Detail)
// 街拍详情:同走秀详情,单条枚举防护由 HashID 承担,不走前端签名。
api.GET("/public/street-snaps/:id", opt.StreetSnap.Detail)
// 账号体系:注册 / 登录 / 登出 / 当前用户(JWT 无状态)
// 账号体系:当前只保留「取当前用户」(JWT 无状态,无服务端登出路由)。
//
// 注册 / 登录接口已从路由移除:前端没有登录注册入口,对外开放即是垃圾账号与撞库入口。
// handler / service / repository / dto 中对应实现一并删除。
// 将来要接入时:补回 POST /auth/register、POST /auth/login,并同步前端 src/lib/api.ts 与登录页。
auth := api.Group("/auth")
{
auth.POST("/register", opt.Auth.Register)
auth.POST("/login", opt.Auth.Login)
auth.GET("/me", middleware.Auth(opt.JWT), opt.Auth.Me)
auth.GET("/me", middleware.Auth(opt.JWT), opt.Auth.Me)
}
}