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.
 
 
 
 
 

34 lines
599 B

'use strict';
const Boards = require(__dirname+'/../../db/boards.js');
module.exports = async (req, res, next) => {
if (!req.query.board) {
return next();
}
//agregate to get single random item from banners array
const board = await Boards.db.aggregate([
{
'$match': {
'_id': req.query.board
}
},
{
'$unwind': '$banners'
},
{
'$sample': {
'size' : 1
}
}
]).toArray().then(res => res[0]);
if (board && board.banners != null) {
return res.redirect(`/banner/${req.query.board}/${board.banners}`);
}
return res.redirect('/img/defaultbanner.png');
}