feat: 添加用户位置、操作系统和浏览器信息到评论功能

This commit is contained in:
2025-09-13 15:08:46 +08:00
parent 44f15e1ff1
commit 011dc298c2
12 changed files with 253 additions and 148 deletions

View File

@ -1,6 +1,7 @@
package model
import (
"github.com/snowykami/neo-blog/pkg/utils"
"gorm.io/gorm"
)
@ -16,6 +17,12 @@ type Comment struct {
IsPrivate bool `gorm:"default:false"` // 是否为私密评论,私密评论只有评论者和被评论对象所有者可见
RemoteAddr string `gorm:"type:text"` // 远程地址
UserAgent string `gorm:"type:text"`
Location string `gorm:"type:text"` // 用户位置基于IP
LikeCount uint64
CommentCount uint64
}
func (c *Comment) AfterCreate(tx *gorm.DB) (err error) {
// 更新评论IP
return tx.Model(c).Update("Location", utils.GetLocationString(c.RemoteAddr)).Error
}