mirror of
https://github.com/wassname/talk.git
synced 2026-07-07 15:13:35 +08:00
35 lines
972 B
JavaScript
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,
|
|
});
|
|
},
|
|
},
|
|
},
|
|
};
|