Files
talk/plugins/talk-plugin-rte/server/hooks.js
T
2018-02-23 12:29:30 -03:00

35 lines
972 B
JavaScript

const { merge, get } = require('lodash');
const DOMPurify = require('dompurify');
const config = require('./config');
module.exports = {
RootMutation: {
createComment: {
async pre(_, { input }, _context, _info) {
// Let's sanitize the body
const dirtyInput = input.htmlBody;
const cleanInput = DOMPurify.sanitize(dirtyInput, config.dompurify);
// Adding the clean body to the comment.metadata field
input.metadata = merge(get(input, 'metadata'), {
htmlBody: cleanInput,
});
},
},
editComment: {
async pre(_, { edit }, _context, _info) {
// Let's sanitize the body
const dirtyInput = edit.htmlBody;
const cleanInput = DOMPurify.sanitize(dirtyInput, config.dompurify);
// Adding the clean body to the comment.metadata field
edit.metadata = merge(get(edit, 'metadata'), {
htmlBody: cleanInput,
});
},
},
},
};