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.
50 lines
1.2 KiB
50 lines
1.2 KiB
'use strict';
|
|
|
|
const { Modlogs } = require(__dirname+'/../../../db/')
|
|
, pageQueryConverter = require(__dirname+'/../../../helpers/pagequeryconverter.js')
|
|
, decodeQueryIP = require(__dirname+'/../../../helpers/decodequeryip.js')
|
|
, limit = 50;
|
|
|
|
module.exports = async (req, res, next) => {
|
|
|
|
const { page, offset, queryString } = pageQueryConverter(req.query, limit);
|
|
|
|
let filter = {};
|
|
const username = (typeof req.query.username === 'string' ? req.query.username : null);
|
|
if (username && !Array.isArray(username)) {
|
|
filter.user = username;
|
|
}
|
|
const uri = (typeof req.query.uri === 'string' ? req.query.uri : null);
|
|
if (uri && !Array.isArray(uri)) {
|
|
filter.board = uri;
|
|
}
|
|
const ipMatch = decodeQueryIP(req.query, res.locals.permLevel);
|
|
if (ipMatch) {
|
|
filter.ip = ipMatch;
|
|
}
|
|
|
|
let logs, maxPage;
|
|
try {
|
|
[logs, maxPage] = await Promise.all([
|
|
Modlogs.find(filter, offset, limit),
|
|
Modlogs.count(filter),
|
|
]);
|
|
maxPage = Math.ceil(maxPage/limit);
|
|
} catch (err) {
|
|
return next(err)
|
|
}
|
|
|
|
res
|
|
.set('Cache-Control', 'private, max-age=5')
|
|
.render('globalmanagelogs', {
|
|
csrf: req.csrfToken(),
|
|
queryString,
|
|
username,
|
|
uri,
|
|
ip: ipMatch ? req.query.ip : null,
|
|
logs,
|
|
page,
|
|
maxPage,
|
|
});
|
|
|
|
}
|
|
|