mirror of
https://github.com/wassname/talk.git
synced 2026-09-09 11:38:08 +08:00
add toxic comments plugin to main api
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
module.exports = (perspective) => {
|
||||
console.log("hello world from perpsctive");
|
||||
if(!process.env.PERSPECTIVE_API_KEY) {
|
||||
throw new Error('Please set the PERSPECTIVE_API_KEY environment variable to use the toxic-comments plugin. Visit https://www.perspectiveapi.com/ to request API access.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
const http = require('axios');
|
||||
const boom = require('express-boom');
|
||||
const bodyParser = require('body-parser');
|
||||
var count = 0;
|
||||
|
||||
module.exports = (router) => {
|
||||
router.use(boom());
|
||||
router.use(bodyParser.text());
|
||||
router.post('/api/v1/toxicity/comments', (req, res) => {
|
||||
console.log(req.body);
|
||||
if(req.body) {
|
||||
var body = {
|
||||
comment: {
|
||||
text: req.body,
|
||||
languages: ["en"],
|
||||
requestedAttributes: {
|
||||
TOXICITY: {}
|
||||
}
|
||||
}
|
||||
};
|
||||
var headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Length': Buffer.byteLength(data)
|
||||
};
|
||||
http.post('https://commentanalyzer.googleapis.com/v1alpha1/comments:analyze?key='+process.env.PERSPECTIVE_API_KEY, {
|
||||
headers: headers,
|
||||
body: body
|
||||
})
|
||||
.then(function(response) {
|
||||
return res.json(response);
|
||||
})
|
||||
.catch(function(err) {
|
||||
return res.json(err);
|
||||
})
|
||||
}
|
||||
else {
|
||||
res.boom.notFound();
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user