This commit is contained in:
Tomas Dvorak
2025-11-14 15:53:12 +01:00
parent f3db65d350
commit c941313fd5
149 changed files with 4366 additions and 12935 deletions
+9 -7
View File
@@ -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)