mirror of
https://github.com/wassname/talk.git
synced 2026-07-19 11:28:50 +08:00
Remove unused code
This commit is contained in:
@@ -3,10 +3,4 @@ en:
|
||||
COMMENT_IS_TOXIC: |
|
||||
Are you sure? The language in this comment might violate our community guidelines.
|
||||
You can edit the comment or submit it for moderator review.
|
||||
talk-plugin-featured-comments:
|
||||
featured: Featured
|
||||
go_to_conversation: Go to conversation
|
||||
es:
|
||||
talk-plugin-featured-comments:
|
||||
featured: Remarcado
|
||||
go_to_conversation: Ir al comentario
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
const {readFileSync} = require('fs');
|
||||
const path = require('path');
|
||||
const router = require('./server/router');
|
||||
const hooks = require('./server/hooks');
|
||||
|
||||
module.exports = {
|
||||
typeDefs: readFileSync(path.join(__dirname, 'server/typeDefs.graphql'), 'utf8'),
|
||||
router,
|
||||
hooks,
|
||||
};
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
const {APIError} = require('../../../errors');
|
||||
|
||||
const ErrNoComment = new APIError('Comment must be provided', {
|
||||
status: 400,
|
||||
});
|
||||
|
||||
const ErrToxic = new APIError('Comment is toxic', {
|
||||
status: 400,
|
||||
translation_key: 'COMMENT_IS_TOXIC',
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
ErrNoComment,
|
||||
ErrToxic,
|
||||
};
|
||||
|
||||
@@ -1,19 +1,8 @@
|
||||
const perspective = require('./perspective');
|
||||
const {ADD_COMMENT_TAG} = require('../../../perms/constants');
|
||||
const {ErrToxic} = require('./errors');
|
||||
const {TOXICITY_THRESHOLD} = require('./constants');
|
||||
|
||||
module.exports = {
|
||||
Comment: {
|
||||
tags: {
|
||||
post(comment, input, {user}, _info, result) {
|
||||
if (comment.metadata.perspective && user && user.can(ADD_COMMENT_TAG)) {
|
||||
return result.concat({tag: {name: 'TOXIC', created_at: new Date()}});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
},
|
||||
},
|
||||
RootMutation: {
|
||||
createComment: {
|
||||
async pre(_, {input}, _context, _info) {
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
const perspective = require('./perspective');
|
||||
const {ErrNoComment} = require('./errors');
|
||||
|
||||
module.exports = (router) => {
|
||||
|
||||
/**
|
||||
* POST /api/v1/toxicity/score
|
||||
* args:
|
||||
* - provide the comment in the request body
|
||||
*/
|
||||
router.post('/api/v1/toxicity/score', async (req, res, next) => {
|
||||
const apiKey = process.env.TALK_PERSPECTIVE_API_KEY;
|
||||
if(!apiKey) {
|
||||
throw new Error('Please set the TALK_PERSPECTIVE_API_KEY environment variable to use the toxic-comments plugin. Visit https://www.perspectiveapi.com/ to request API access.');
|
||||
}
|
||||
|
||||
const {comment} = req.body;
|
||||
|
||||
if(!comment) {
|
||||
return next(ErrNoComment);
|
||||
}
|
||||
|
||||
try {
|
||||
const scores = await perspective.getScores(apiKey, comment);
|
||||
return res.json({
|
||||
comment,
|
||||
score: scores.SEVERE_TOXICITY.summaryScore,
|
||||
});
|
||||
} catch(err) {
|
||||
return next(err);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user