mirror of https://gitgud.io/fatchan/jschan.git
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.
86 lines
2.4 KiB
86 lines
2.4 KiB
'use strict';
|
|
|
|
const { enableWebring } = require(__dirname+'/../../configs/main.js')
|
|
, { Boards, Webring } = require(__dirname+'/../../db/')
|
|
, { relativeColor, relativeString } = require(__dirname+'/../../helpers/timeutils.js')
|
|
, pageQueryConverter = require(__dirname+'/../../helpers/pagequeryconverter.js')
|
|
, limit = 20;
|
|
|
|
module.exports = async (req, res, next) => {
|
|
|
|
const isGlobalStaff = res.locals.permLevel <= 1;
|
|
const { page, offset, queryString } = pageQueryConverter(req.query, limit);
|
|
const direction = req.query.direction && req.query.direction === 'asc' ? 1 : -1;
|
|
let sort;
|
|
if (req.query.sort && req.query.sort === 'activity') {
|
|
sort = {
|
|
'lastPostTimestamp': direction
|
|
}
|
|
} else {
|
|
sort = {
|
|
'ips': direction,
|
|
'pph': direction,
|
|
'sequence_value': direction
|
|
};
|
|
}
|
|
|
|
let filter = {};
|
|
const search = (typeof req.query.search === 'string' ? req.query.search : null);
|
|
if (req.query.search && search) {
|
|
filter = {
|
|
'search': search
|
|
}
|
|
}
|
|
|
|
let localBoards, webringBoards, localPages, webringPages;
|
|
try {
|
|
[ localBoards, localPages, webringBoards, webringPages ] = await Promise.all([
|
|
Boards.boardSort(offset, limit, sort, filter, isGlobalStaff),
|
|
Boards.count(filter, isGlobalStaff),
|
|
enableWebring ? Webring.boardSort(offset, limit, sort, filter, isGlobalStaff) : null,
|
|
enableWebring ? Webring.count(filter) : 0,
|
|
]);
|
|
localPages = Math.ceil(localPages / limit);
|
|
webringPages = Math.ceil(webringPages / limit);
|
|
} catch (err) {
|
|
return next(err);
|
|
}
|
|
const maxPage = Math.max(localPages, webringPages);
|
|
|
|
const now = new Date();
|
|
if (localBoards) {
|
|
for (let i = 0; i < localBoards.length; i++) {
|
|
if (localBoards[i].lastPostTimestamp) {
|
|
const lastPostDate = new Date(localBoards[i].lastPostTimestamp);
|
|
localBoards[i].lastPostTimestamp = {
|
|
text: relativeString(now, lastPostDate),
|
|
color: relativeColor(now, lastPostDate)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (webringBoards) {
|
|
for (let i = 0; i < webringBoards.length; i++) {
|
|
if (webringBoards[i].lastPostTimestamp) {
|
|
const lastPostDate = new Date(webringBoards[i].lastPostTimestamp);
|
|
webringBoards[i].lastPostTimestamp = {
|
|
text: relativeString(now, lastPostDate),
|
|
color: relativeColor(now, lastPostDate)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
res
|
|
.set('Cache-Control', 'private, max-age=60')
|
|
.render('boardlist', {
|
|
localBoards,
|
|
webringBoards,
|
|
page,
|
|
maxPage,
|
|
query: req.query,
|
|
search,
|
|
queryString,
|
|
});
|
|
|
|
}
|
|
|