Skip to content

Commit e20e193

Browse files
authored
Merge pull request #515 from LydiaCai1203/fix-target-active
fix: 部分接口缺失活跃时间记录
2 parents c33c010 + df42b79 commit e20e193

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

backend/biz/project/handler/v1/project.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ func NewProjectHandler(i *do.Injector) (*ProjectHandler, error) {
3939
g.DELETE("/:id", web.BindHandler(h.Delete))
4040

4141
gi := w.Group("/api/v1/users/projects/:id/issues")
42-
gi.Use(auth.Auth())
42+
gi.Use(auth.Auth(), targetActive.TargetActive())
4343
gi.GET("", web.BindHandler(h.ListIssues))
4444
gi.POST("", web.BindHandler(h.CreateIssue))
4545
gi.PUT("/:issue_id", web.BindHandler(h.UpdateIssue))
4646

4747
gic := w.Group("/api/v1/users/projects/:id/issues/:issue_id/comments")
48-
gic.Use(auth.Auth())
48+
gic.Use(auth.Auth(), targetActive.TargetActive())
4949
gic.GET("", web.BindHandler(h.ListIssueComments))
5050
gic.POST("", web.BindHandler(h.CreateIssueComment))
5151

5252
gc := w.Group("/api/v1/users/projects/:id/collaborators")
53-
gc.Use(auth.Auth())
53+
gc.Use(auth.Auth(), targetActive.TargetActive())
5454
gc.GET("", web.BindHandler(h.ListCollaborators))
5555

5656
gt := w.Group("/api/v1/users/projects/:id/tree")
57-
gt.Use(auth.Auth())
57+
gt.Use(auth.Auth(), targetActive.TargetActive())
5858
gt.GET("", web.BindHandler(h.GetProjectTree))
5959
gt.GET("/blob", web.BindHandler(h.GetProjectBlob))
6060
gt.GET("/logs", web.BindHandler(h.GetProjectLogs))

backend/biz/task/handler/v1/task.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type TaskHandler struct {
4747
controlConns *ws.ControlConn
4848
taskSummary *service.TaskSummaryService
4949
idleRefresher vmidle.VMIdleRefresher
50+
activeRepo domain.UserActiveRepo
5051
}
5152

5253
// NewTaskHandler 创建任务处理器
@@ -76,6 +77,8 @@ func NewTaskHandler(i *do.Injector) (*TaskHandler, error) {
7677
nlsSvc = n
7778
}
7879

80+
activeRepo := do.MustInvoke[domain.UserActiveRepo](i)
81+
7982
h := &TaskHandler{
8083
cfg: cfg,
8184
usecase: uc,
@@ -89,6 +92,7 @@ func NewTaskHandler(i *do.Injector) (*TaskHandler, error) {
8992
controlConns: cc,
9093
taskSummary: ts,
9194
idleRefresher: ir,
95+
activeRepo: activeRepo,
9296
}
9397

9498
// 注册路由
@@ -583,6 +587,11 @@ func (h *TaskHandler) readClientMessages(ctx context.Context, wsConn *ws.Websock
583587
}
584588

585589
func (h *TaskHandler) handleClientMessage(ctx context.Context, logger *slog.Logger, user *domain.User, task *domain.Task, m domain.TaskStream) {
590+
// 记录用户活跃时间
591+
if err := h.activeRepo.RecordActiveRecord(ctx, consts.UserActiveKey, user.ID.String(), time.Now()); err != nil {
592+
logger.With("error", err).WarnContext(ctx, "failed to record user active time")
593+
}
594+
586595
switch m.Type {
587596
case consts.TaskStreamTypeUserInput:
588597
if err := h.usecase.Continue(ctx, user, task.ID, string(m.Data)); err != nil {

backend/biz/user/handler/v1/auth.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ func NewAuthHandler(i *do.Injector) (*AuthHandler, error) {
5656
v1.PUT("/passwords/reset", web.BindHandler(h.ResetPassword))
5757

5858
// 密码登录
59-
v1.POST("/password-login", web.BindHandler(h.PasswordLogin))
60-
v1.PUT("/passwords/change", web.BindHandler(h.ChangePassword), auth.Check())
61-
v1.GET("/status", web.BaseHandler(h.Status), auth.Check())
59+
v1.POST("/password-login", web.BindHandler(h.PasswordLogin), targetActive.TargetActive())
60+
v1.PUT("/passwords/change", web.BindHandler(h.ChangePassword), auth.Check(), targetActive.TargetActive())
61+
v1.GET("/status", web.BaseHandler(h.Status), auth.Check(), targetActive.TargetActive())
6262
v1.POST("/logout", web.BaseHandler(h.Logout), auth.Auth(), targetActive.TargetActive())
6363

6464
// 邮箱绑定接口
6565
v1.PUT("/email/bind-request", web.BindHandler(h.SendBindEmailVerification), auth.Auth(), targetActive.TargetActive())
66-
v1.GET("/email/verify", web.BindHandler(h.VerifyBindEmail))
66+
v1.GET("/email/verify", web.BindHandler(h.VerifyBindEmail), targetActive.TargetActive())
6767

6868
return h, nil
6969
}

0 commit comments

Comments
 (0)