feat: add hook system, QR code login, and layered cache
All checks were successful
Build Backend / build (push) Successful in 5m54s
Build Backend / build-docker (push) Successful in 4m7s

- Implement extensible hook system for content moderation with
  builtin and AI-powered moderation hooks
- Add QR code login feature with SSE for real-time status updates
  and scan/confirm/cancel workflow
- Introduce layered cache with local LRU + Redis backend for
  improved read performance
- Refactor post and comment services to use hook-based moderation
  instead of direct AI service calls
- Add local cache configuration options (size, buckets, ttl)
This commit is contained in:
lafay
2026-03-20 12:23:28 +08:00
parent bdfcbdadea
commit 98f0c9f2b6
23 changed files with 2726 additions and 76 deletions

View File

@@ -32,6 +32,7 @@ type Router struct {
adminGroupHandler *handler.AdminGroupHandler
adminDashboardHandler *handler.AdminDashboardHandler
adminLogHandler *handler.AdminLogHandler
qrcodeHandler *handler.QRCodeHandler
logService *service.LogService
jwtService *service.JWTService
casbinService service.CasbinService
@@ -60,6 +61,7 @@ func New(
adminGroupHandler *handler.AdminGroupHandler,
adminDashboardHandler *handler.AdminDashboardHandler,
adminLogHandler *handler.AdminLogHandler,
qrcodeHandler *handler.QRCodeHandler,
logService *service.LogService,
activityService service.UserActivityService,
casbinService service.CasbinService,
@@ -91,6 +93,7 @@ func New(
adminGroupHandler: adminGroupHandler,
adminDashboardHandler: adminDashboardHandler,
adminLogHandler: adminLogHandler,
qrcodeHandler: qrcodeHandler,
logService: logService,
jwtService: jwtService,
casbinService: casbinService,
@@ -183,6 +186,24 @@ func (r *Router) setupRoutes() {
users.GET("/:id/favorites", middleware.OptionalAuth(r.jwtService), r.postHandler.GetFavorites)
}
// 二维码登录(公开)
if r.qrcodeHandler != nil {
qrcode := v1.Group("/auth/qrcode")
{
qrcode.GET("", r.qrcodeHandler.GetQRCode)
qrcode.GET("/events", r.qrcodeHandler.SSEEvents)
}
// 二维码操作(需认证)
qrcodeAuth := v1.Group("/auth/qrcode")
qrcodeAuth.Use(authMiddleware)
{
qrcodeAuth.POST("/scan", r.qrcodeHandler.Scan)
qrcodeAuth.POST("/confirm", r.qrcodeHandler.Confirm)
qrcodeAuth.POST("/cancel", r.qrcodeHandler.Cancel)
}
}
// 认证路由(公开)
authPublic := v1.Group("/auth")
{