代码拉取完成,页面将自动刷新
const AV = require('leanengine');
const mail = require('./utilities/send-mail');
const Comment = AV.Object.extend('Comment');
const request = require('request');
const spam = require('./utilities/check-spam');
function sendNotification(currentComment, defaultIp) {
// 发送博主通知邮件
if (currentComment.get('mail') !== process.env.BLOGGER_EMAIL) {
mail.notice(currentComment);
}
let ip = currentComment.get('ip') || defaultIp;
console.log('IP: %s', ip);
spam.checkSpam(currentComment, ip);
// AT评论通知
let rid =currentComment.get('pid') || currentComment.get('rid');
if (!rid) {
console.log("这条评论没有 @ 任何人");
return;
} else if (currentComment.get('isSpam')) {
console.log('评论未通过审核,通知邮件暂不发送');
return;
}
let query = new AV.Query('Comment');
query.get(rid).then(function (parentComment) {
if (parentComment.get('mail') && parentComment.get('mail') !== process.env.BLOGGER_EMAIL) {
mail.send(currentComment, parentComment);
} else {
console.log('被@者匿名,不会发送通知');
}
}, function (error) {
console.warn('获取@对象失败!');
});
}
AV.Cloud.afterSave('Comment', function (req) {
let currentComment = req.object;
// 检查垃圾评论
return sendNotification(currentComment, req.meta.remoteAddress);
});
AV.Cloud.define('resend_mails', function(req) {
let query = new AV.Query(Comment);
query.greaterThanOrEqualTo('createdAt', new Date(new Date().getTime() - 24*60*60*1000));
query.notEqualTo('isNotified', true);
// 如果你的评论量很大,可以适当调高数量限制,最高1000
query.limit(200);
return query.find().then(function(results) {
new Promise((resolve, reject)=>{
count = results.length;
for (var i = 0; i < results.length; i++ ) {
sendNotification(results[i], req.meta.remoteAddress);
}
resolve(count);
}).then((count)=>{
console.log(`昨日${count}条未成功发送的通知邮件处理完毕!`);
}).catch(()=>{
});
});
});
AV.Cloud.define('self_wake', function(req) {
request(process.env.ADMIN_URL, function (error, response, body) {
console.log('自唤醒任务执行成功,响应状态码为:', response && response.statusCode);
});
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。