feat(moderation): make moderation more lenient and add timeout fallback behavior
The moderation system now uses a "pass/review" strategy instead of "pass/review/block", treating hard violations the same as review (only routing to manual review rather than auto-rejecting). Add fallback-approve behavior in the hook system so slow moderation APIs never silently block normal content when they time out or get cancelled - timed-out moderation now approves with "ReviewedBy: system" instead of leaving the zero-value result that would reject content. Update post/comment/vote services and handlers to use the new unified behavior. Simplify moderation prompts to emphasize "宁可放过,不可误伤" (prefer false positives over false negatives).
This commit is contained in:
@@ -2,6 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
@@ -170,7 +171,7 @@ func (s *commentService) reviewCommentAsync(
|
||||
fmt.Sscanf(userID, "%d", &authorID)
|
||||
|
||||
result := &hook.ModerationResult{}
|
||||
s.hookManager.TriggerWithMetadata(context.Background(), hook.HookCommentPreModerate, authorID, &hook.CommentModerateHookData{
|
||||
triggerErr := s.hookManager.TriggerWithMetadata(context.Background(), hook.HookCommentPreModerate, authorID, &hook.CommentModerateHookData{
|
||||
CommentID: commentID,
|
||||
PostID: postID,
|
||||
Content: content,
|
||||
@@ -181,6 +182,19 @@ func (s *commentService) reviewCommentAsync(
|
||||
"result": result,
|
||||
})
|
||||
|
||||
// Fallback-approve when a moderation hook times out or is cancelled, so a
|
||||
// slow moderation API never silently rejects an otherwise-fine comment.
|
||||
if triggerErr != nil && (errors.Is(triggerErr, context.DeadlineExceeded) || errors.Is(triggerErr, context.Canceled)) {
|
||||
zap.L().Warn("Comment moderation hook timed out or was cancelled, fallback approve",
|
||||
zap.String("comment_id", commentID),
|
||||
zap.Error(triggerErr),
|
||||
)
|
||||
result.Approved = true
|
||||
result.ReviewedBy = "system"
|
||||
result.RejectReason = ""
|
||||
result.NeedsReview = false
|
||||
}
|
||||
|
||||
s.hookManager.Trigger(context.Background(), hook.HookCommentModerated, authorID, &hook.CommentModeratedHookData{
|
||||
CommentID: commentID,
|
||||
PostID: postID,
|
||||
|
||||
Reference in New Issue
Block a user