mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-03 18:22:57 +00:00
dev day #92
This commit is contained in:
@@ -386,6 +386,7 @@ type commentOutput struct {
|
||||
TargetLabel string `json:"target_label,omitempty"`
|
||||
ParentID *uint `json:"parent_id,omitempty"`
|
||||
Content string `json:"content"`
|
||||
ContentHTML string `json:"content_html,omitempty"`
|
||||
Status string `json:"status"`
|
||||
IsEdited bool `json:"is_edited"`
|
||||
EditedAt *time.Time `json:"edited_at"`
|
||||
@@ -542,6 +543,9 @@ func (cc *CommentController) GetComments(c *gin.Context) {
|
||||
|
||||
for _, r := range rows {
|
||||
co := toOutput(r)
|
||||
if role != "admin" {
|
||||
co.ContentHTML = services.MaskBadWordsHTML(co.Content)
|
||||
}
|
||||
if co.User.ID != 0 {
|
||||
if p, ok := profByUser[co.User.ID]; ok {
|
||||
if strings.TrimSpace(p.Username) != "" { co.User.Username = p.Username }
|
||||
@@ -620,12 +624,11 @@ func (cc *CommentController) CreateComment(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Spam evaluation and bad words filtering
|
||||
// Spam evaluation and moderation (do not alter stored content)
|
||||
score, rules := services.EvaluateSpamScore(content)
|
||||
filtered, _ := services.FilterBadWords(content)
|
||||
status := "visible"
|
||||
// Moderation only if sensitive terms detected
|
||||
if ok, _ := services.ContainsSensitiveWords(filtered); ok {
|
||||
if ok, _ := services.ContainsSensitiveWords(content); ok {
|
||||
status = "hidden"
|
||||
}
|
||||
rulesJSON, _ := json.Marshal(rules)
|
||||
@@ -635,7 +638,7 @@ func (cc *CommentController) CreateComment(c *gin.Context) {
|
||||
TargetID: in.TargetID,
|
||||
UserID: userID,
|
||||
ParentID: in.ParentID,
|
||||
Content: filtered,
|
||||
Content: content,
|
||||
Status: status,
|
||||
SpamScore: float32(score),
|
||||
SpamRules: string(rulesJSON),
|
||||
@@ -701,11 +704,10 @@ func (cc *CommentController) UpdateComment(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// Filter & re-evaluate basic spam (do not auto-hide unless sensitive)
|
||||
// Re-evaluate basic spam, keep original content (masking is done on output)
|
||||
score, rules := services.EvaluateSpamScore(content)
|
||||
filtered, _ := services.FilterBadWords(content)
|
||||
now := time.Now()
|
||||
cm.Content = filtered
|
||||
cm.Content = content
|
||||
cm.IsEdited = true
|
||||
cm.EditedAt = &now
|
||||
cm.SpamScore = float32(score)
|
||||
|
||||
Reference in New Issue
Block a user