Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加百度内容审核功能 #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ SENDER_EMAIL | [email protected] | [必填]发件邮箱
ADMIN_URL | https://xxx.leanapp.cn/ | [建议]Web主机二级域名,用于自动唤醒
BLOGGER_EMAIL | [email protected] | [可选]博主通知收件地址,默认使用SENDER_EMAIL
AKISMET_KEY | xxxxxxxxxxxx | [可选]Akismet Key 用于垃圾评论检测,设为MANUAL_REVIEW开启人工审核,留空不使用反垃圾

BAIDU_APPID | xxxxxxxxxxxx | [可选]百度云内容审核引擎APPID(用于垃圾评论检测,设为MANUAL_REVIEW开启人工审核,优先级高于AKISMET_KEY,若配置则优先使用Baidu内容审核)
BAIDU_APIKEY | xxxxxxxxxxxx | [可选]若启用百度内容审核则必填,可前往https://ai.baidu.com/censoring 配置审核策略和申请应用AK SK
BAIDU_SECRET | xxxxxxxxxxxx | [可选]若启用百度内容审核则必填
</div>

**以上必填参数请务必正确设置。**
Expand Down Expand Up @@ -148,6 +150,27 @@ COMMENT | 新评论内容
--- | ------ | ------
AKISMET_KEY | xxxxxxxxxxxx | [可选]Akismet Key 用于垃圾评论检测

## 百度AI垃圾评论检测

> 使用百度内容审核平台替代Akismet的审核功能,白名单和黑名单的提交功能由于百度没有开放接口所以只能在百度后台进行配置。
> 相比于Akismet,百度内容审核平台属于付费产品,但个人有一定免费额度(文本接口实名认证后累计50万次调用,还有图像接口,详见[计费规则](https://ai.baidu.com/ai-doc/ANTIPORN/lk3h6x7if))
> 百度审核只审核评论的内容,不需要任何用户信息,相比Akismet来说更加简单直接。同时支持配置[自定义审核策略](https://ai.baidu.com/censoring),可对色情、暴恐、政治敏感、恶意推广、低俗辱骂、低质灌水等内容进行阈值自定义调整,使用上更加灵活方便。
> 同时由于百度没有提供黑白名单的API接口(通过配置策略自主上传),所以如果选择了百度审核,则本管理后台的黑白名单的功能将不会生效,请前往百度后台自主配置。

如果还没有百度云账号,你可以去百度大脑的 [AI开放平台](https://ai.baidu.com/tech/textcensoring) 免费申请一个;

**当BAIDU_APPID设为MANUAL_REVIEW时,开启人工审核模式;**
如果你不需要反垃圾评论,BAIDU_APPID环境变量可以忽略。

~~**为了实现较为精准的垃圾评论识别,采集的判据除了评论内容、邮件地址和网站地址外,还包括评论者的IP地址、浏览器信息等,但仅在云引擎后台使用这些数据,确保隐私和安全。**~~
百度审核不需要这些内容

环境变量 | 示例 | 说明
--- | ------ | ------
BAIDU_APPID | xxxxxxxxxxxx | [可选]百度云内容审核引擎APPID(用于垃圾评论检测,设为MANUAL_REVIEW开启人工审核,优先级高于AKISMET_KEY,若配置则优先使用Baidu内容审核)
BAIDU_APIKEY | xxxxxxxxxxxx | [可选]若启用百度内容审核则必填,可前往https://ai.baidu.com/censoring 配置审核策略和申请应用AK SK
BAIDU_SECRET | xxxxxxxxxxxx | [可选]若启用百度内容审核则必填

## 防止云引擎休眠

关于自动休眠的官方说法:[点击查看](https://leancloud.cn/docs/leanengine_plan.html#hash633315134)
Expand Down
45 changes: 21 additions & 24 deletions cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ const Comment = AV.Object.extend('Comment');
const request = require('request');
const spam = require('./utilities/check-spam');

function sendNotification(currentComment, defaultIp) {
async 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);
await spam.checkSpam(currentComment, ip);

// AT评论通知
let rid =currentComment.get('pid') || currentComment.get('rid');
let rid = currentComment.get('pid') || currentComment.get('rid');

if (!rid) {
console.log("这条评论没有 @ 任何人");
Expand All @@ -26,16 +26,14 @@ function sendNotification(currentComment, defaultIp) {
}

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('获取@对象失败!');
let parentComment = await query.get(rid).catch(err => {
return console.warn('获取@对象失败!');
});
if (parentComment.get('mail') && parentComment.get('mail') !== process.env.BLOGGER_EMAIL) {
mail.send(currentComment, parentComment);
} else {
console.log('被@者匿名,不会发送通知');
}
}

AV.Cloud.afterSave('Comment', function (req) {
Expand All @@ -44,30 +42,29 @@ AV.Cloud.afterSave('Comment', function (req) {
return sendNotification(currentComment, req.meta.remoteAddress);
});

AV.Cloud.define('resend_mails', function(req) {
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.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)=>{
return query.find().then(function (results) {
new Promise((resolve, reject) => {
count = results.length;
for (var i = 0; i < results.length; i++ ) {
for (var i = 0; i < results.length; i++) {
sendNotification(results[i], req.meta.remoteAddress);
}
resolve(count);
}).then((count)=>{
}).then((count) => {
console.log(`昨日${count}条未成功发送的通知邮件处理完毕!`);
}).catch(()=>{
}).catch(() => {

});
});
});
});

AV.Cloud.define('self_wake', function(req) {
AV.Cloud.define('self_wake', function (req) {
request(process.env.ADMIN_URL, function (error, response, body) {
console.log('自唤醒任务执行成功,响应状态码为:', response && response.statusCode);
});
});

});
});
Loading