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.

44 lines
1.1 KiB

'use strict';
const cache = require(__dirname+'/../../redis.js')
, { enableWebring } = require(__dirname+'/../../configs/main.json')
, { Boards } = require(__dirname+'/../../db/')
, limit = 20;
module.exports = async (req, res, next) => {
let page;
if (req.query.page && Number.isSafeInteger(parseInt(req.query.page))) {
page = parseInt(req.query.page);
if (page <= 0) {
page = 1;
}
} else {
page = 1;
}
const offset = (page-1) * limit;
let boards, webringBoards, localPages, webringPages;
try {
[ boards, webringBoards, localPages ] = await Promise.all([
Boards.boardSort(offset, limit),
enableWebring ? cache.get('webring:boards') : null,
Boards.count(),
]);
} catch (err) {
return next(err);
}
localPages = Math.ceil(localPages / limit);
if (enableWebring && webringBoards) { //sort webring boards
webringPages = Math.ceil(webringBoards.length / limit);
webringBoards = webringBoards.sort((a, b) => { return b.uniqueUsers - a.uniqueUsers }).splice(offset, limit);
}
const maxPage = Math.max(localPages, webringPages);
return res.render('boardlist', {
boards,
webringBoards,
page,
maxPage
});
}