31 lines
700 B
JavaScript
31 lines
700 B
JavaScript
const fs = require("fs");
|
|
|
|
function reviewPost(filePath, postId) {
|
|
const raw = fs.readFileSync(filePath, "utf8");
|
|
const state = JSON.parse(raw);
|
|
const post = state.posts.find((item) => item.id === postId);
|
|
|
|
if (!post) {
|
|
throw new Error("Post not found");
|
|
}
|
|
|
|
let action = "approve";
|
|
|
|
if (post.text.includes("buy now") || post.text.includes("free money")) {
|
|
action = "reject";
|
|
}
|
|
|
|
if (post.reports > 3) {
|
|
action = "escalate";
|
|
}
|
|
|
|
post.status = action;
|
|
post.reviewedAt = new Date().toISOString();
|
|
fs.writeFileSync(filePath, JSON.stringify(state, null, 2));
|
|
console.log("Moderation action", postId, action);
|
|
|
|
return { action };
|
|
}
|
|
|
|
module.exports = { reviewPost };
|