From f7b2022f59c8fa108f22ba83531fa97958128228 Mon Sep 17 00:00:00 2001 From: Snowykami Date: Fri, 12 Sep 2025 15:54:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E5=AD=97=E6=AE=B5=E5=88=B0=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=94=AF=E6=8C=81=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=9A=84=E7=94=A8=E6=88=B7=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/controller/v1/comment.go | 1 + internal/dto/comment.go | 1 + internal/model/comment.go | 1 + internal/service/comment.go | 1 + 4 files changed, 4 insertions(+) diff --git a/internal/controller/v1/comment.go b/internal/controller/v1/comment.go index fbfe06a..e4cf356 100644 --- a/internal/controller/v1/comment.go +++ b/internal/controller/v1/comment.go @@ -32,6 +32,7 @@ func (cc *CommentController) CreateComment(ctx context.Context, c *app.RequestCo return } req.RemoteAddr = c.RemoteAddr().String() + req.UserAgent = string(c.UserAgent()) commentID, err := cc.service.CreateComment(ctx, &req) if err != nil { serviceErr := errs.AsServiceError(err) diff --git a/internal/dto/comment.go b/internal/dto/comment.go index 7a26f67..628b9a5 100644 --- a/internal/dto/comment.go +++ b/internal/dto/comment.go @@ -23,6 +23,7 @@ type CreateCommentReq struct { ReplyID uint `json:"reply_id"` // 回复的评论ID IsPrivate bool `json:"is_private"` // 是否私密评论,默认false RemoteAddr string `json:"remote_addr"` // 远程地址 + UserAgent string `json:"user_agent"` // 用户代理 } type UpdateCommentReq struct { diff --git a/internal/model/comment.go b/internal/model/comment.go index 902d953..30649c1 100644 --- a/internal/model/comment.go +++ b/internal/model/comment.go @@ -15,6 +15,7 @@ type Comment struct { Depth int `gorm:"default:0"` // 评论的层级深度,从0开始计数 IsPrivate bool `gorm:"default:false"` // 是否为私密评论,私密评论只有评论者和被评论对象所有者可见 RemoteAddr string `gorm:"type:text"` // 远程地址 + UserAgent string `gorm:"type:text"` LikeCount uint64 CommentCount uint64 } diff --git a/internal/service/comment.go b/internal/service/comment.go index a839aea..d99e255 100644 --- a/internal/service/comment.go +++ b/internal/service/comment.go @@ -40,6 +40,7 @@ func (cs *CommentService) CreateComment(ctx context.Context, req *dto.CreateComm UserID: currentUser.ID, IsPrivate: req.IsPrivate, RemoteAddr: req.RemoteAddr, + UserAgent: req.UserAgent, } commentID, err := repo.Comment.CreateComment(comment)