77 lines
2.3 KiB
JavaScript
77 lines
2.3 KiB
JavaScript
/**
|
|
* Moderation helpers for comments and posts (Persian profanity + explicit cues).
|
|
*/
|
|
const { isVerifiedBadge } = require('./verifyBadge')
|
|
|
|
const PROFANITY_PATTERNS = [
|
|
/\b(کس|کیر|کون|جنده|حروم|لاشی|بی\s*شعور|گه|گایید|گائید)\b/i,
|
|
/\b(fuck|shit|bitch|asshole)\b/i
|
|
]
|
|
|
|
const EXPLICIT_CONTENT_PATTERNS = [
|
|
/\b(برهنگ|برهنگی|پورن|porn|nude|naked|sex)\b/i,
|
|
/\b(سکس|جنسی\s*صریح)\b/i
|
|
]
|
|
|
|
function normalizeText (text) {
|
|
if (!text || typeof text !== 'string') return ''
|
|
return text
|
|
.replace(/[\u200c\u200f]/g, '')
|
|
.replace(/\s+/g, ' ')
|
|
.trim()
|
|
}
|
|
|
|
function matchesAny (text, patterns) {
|
|
const normalized = normalizeText(text)
|
|
if (!normalized) return false
|
|
return patterns.some((pattern) => pattern.test(normalized))
|
|
}
|
|
|
|
function containsProfanity (text) {
|
|
return matchesAny(text, PROFANITY_PATTERNS)
|
|
}
|
|
|
|
function containsExplicitContent (text) {
|
|
return matchesAny(text, EXPLICIT_CONTENT_PATTERNS)
|
|
}
|
|
|
|
/**
|
|
* Comment / vitrine / academy comment status.
|
|
* کاربرِ بدون تیک وریفای (طلایی/سبز/آبی) نباید مستقیم توی اپ/وب نمایش داده بشه —
|
|
* باید توی پنل ادمین دستی تایید بشه، پس status روش pending میمونه
|
|
*/
|
|
function resolveCommentModerationStatus (text, verifyBadge) {
|
|
if (containsProfanity(text) || containsExplicitContent(text)) {
|
|
return 'rejected'
|
|
}
|
|
if (!isVerifiedBadge(verifyBadge)) {
|
|
return 'pending'
|
|
}
|
|
return 'temp_accept'
|
|
}
|
|
|
|
/**
|
|
* Post moderation:
|
|
* - reject: profanity / explicit text in caption
|
|
* - pending: creator ندارد تیک وریفای طلایی/سبز/آبی — نیاز به تاییدِ دستیِ پنل داره
|
|
* - temp_accept: creator وریفایشدهست — مستقیم توی اپ نمایش داده میشه
|
|
*/
|
|
function resolvePostModerationStatus ({ caption, filePaths = [], verifyBadge }) {
|
|
if (containsProfanity(caption) || containsExplicitContent(caption)) {
|
|
return { status: 'reject', reason: 'caption_violation' }
|
|
}
|
|
|
|
if (!isVerifiedBadge(verifyBadge)) {
|
|
return { status: 'pending', reason: 'awaiting_admin_review' }
|
|
}
|
|
|
|
return { status: 'temp_accept', reason: 'awaiting_review' }
|
|
}
|
|
|
|
module.exports = {
|
|
containsProfanity,
|
|
containsExplicitContent,
|
|
resolveCommentModerationStatus,
|
|
resolvePostModerationStatus
|
|
}
|