full
This commit is contained in:
63
utils/contentModeration.js
Normal file
63
utils/contentModeration.js
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Moderation helpers for comments and posts (Persian profanity + explicit cues).
|
||||
*/
|
||||
|
||||
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 */
|
||||
function resolveCommentModerationStatus(text) {
|
||||
if (containsProfanity(text) || containsExplicitContent(text)) {
|
||||
return 'rejected';
|
||||
}
|
||||
return 'temp_accept';
|
||||
}
|
||||
|
||||
/**
|
||||
* Post moderation:
|
||||
* - reject: profanity / explicit text in caption
|
||||
* - temp_accept: visible in app, awaits manual full approval
|
||||
*/
|
||||
function resolvePostModerationStatus({ caption, filePaths = [] }) {
|
||||
if (containsProfanity(caption) || containsExplicitContent(caption)) {
|
||||
return { status: 'reject', reason: 'caption_violation' };
|
||||
}
|
||||
|
||||
return { status: 'temp_accept', reason: 'awaiting_review' };
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
containsProfanity,
|
||||
containsExplicitContent,
|
||||
resolveCommentModerationStatus,
|
||||
resolvePostModerationStatus,
|
||||
};
|
||||
Reference in New Issue
Block a user