@@ -29,10 +29,12 @@ type Module struct {
2929 DomainRepo * repo.DomainRepo
3030 SettingsRepo * repo.SettingsRepo
3131 LinkRepo * repo.LinkRepo
32+ AccessLogRepo * repo.AccessLogRepo
3233 UserService * service.UserService
3334 LinkService * service.LinkService
3435 AuthHandler * handlers.AuthHandler
3536 LinkHandler * handlers.LinkHandler
37+ RedirectHandler * handlers.RedirectHandler
3638}
3739
3840// New 创建 v2 模块
@@ -53,12 +55,14 @@ func New() (*Module, error) {
5355 domainRepo := repo .NewDomainRepo (pool )
5456 settingsRepo := repo .NewSettingsRepo (pool )
5557 linkRepo := repo .NewLinkRepo (pool )
58+ accessLogRepo := repo .NewAccessLogRepo (pool )
5659
5760 userService := service .NewUserService (userRepo )
58- linkService := service .NewLinkService (cfg .BaseURL , cfg .MinCodeLength , cfg .MaxCodeLength , linkRepo , domainRepo , settingsRepo , userRepo )
61+ linkService := service .NewLinkService (cfg .BaseURL , cfg .MinCodeLength , cfg .MaxCodeLength , linkRepo , domainRepo , settingsRepo , userRepo , accessLogRepo )
5962
6063 authHandler := handlers .NewAuthHandler (cfg , userService )
6164 linkHandler := handlers .NewLinkHandler (cfg , linkService , linkRepo , domainRepo )
65+ redirectHandler := handlers .NewRedirectHandler (linkService )
6266
6367 return & Module {
6468 Cfg : cfg ,
@@ -67,10 +71,12 @@ func New() (*Module, error) {
6771 DomainRepo : domainRepo ,
6872 SettingsRepo : settingsRepo ,
6973 LinkRepo : linkRepo ,
74+ AccessLogRepo : accessLogRepo ,
7075 UserService : userService ,
7176 LinkService : linkService ,
7277 AuthHandler : authHandler ,
7378 LinkHandler : linkHandler ,
79+ RedirectHandler : redirectHandler ,
7480 }, nil
7581}
7682
@@ -85,6 +91,9 @@ func (m *Module) Close() {
8591func RegisterRoutes (router * gin.Engine , m * Module ) {
8692 utils .LogInfo ("挂载重写版路由:/api/v2" )
8793
94+ // 重写版 redirect(替换 legacy 的任意域名查询,修复多域名 code 冲突风险)
95+ router .GET ("/:code" , m .RedirectHandler .Redirect )
96+
8897 api := router .Group ("/api/v2" )
8998 {
9099 authGroup := api .Group ("/auth" )
0 commit comments