jschan - Anonymous imageboard software. Classic look, modern features and feel. Works without JavaScript and supports Tor, I2P, Lokinet, etc.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB

'use strict';
const News = require(__dirname+'/../../db/news.js')
, uploadDirectory = require(__dirname+'/../../helpers/files/uploadDirectory.js')
, { buildNews } = require(__dirname+'/../../helpers/build.js')
, linkQuotes = require(__dirname+'/../../helpers/posting/quotes.js')
, simpleMarkdown = require(__dirname+'/../../helpers/posting/markdown.js')
, escape = require(__dirname+'/../../helpers/posting/escape.js')
, sanitizeOptions = require(__dirname+'/../../helpers/posting/sanitizeoptions.js')
, sanitize = require('sanitize-html');
module.exports = async (req, res, next) => {
const escaped = escape(req.body.message);
const styled = simpleMarkdown(escaped);
const quoted = (await linkQuotes(null, styled, null)).quotedMessage;
const sanitized = sanitize(quoted, sanitizeOptions.after);
const post = {
'title': req.body.title,
'message': {
'raw': req.body.message,
'markdown': sanitized
},
'date': new Date(),
};
await News.insertOne(post);
await buildNews();
return res.render('message', {
'title': 'Success',
'message': 'Added newspost',
'redirect': '/globalmanage.html'
});
}