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.
51 lines
1.0 KiB
51 lines
1.0 KiB
'use strict';
|
|
|
|
const { Accounts } = require(__dirname+'/../../../db/')
|
|
, pageQueryConverter = require(__dirname+'/../../../helpers/pagequeryconverter.js')
|
|
, limit = 20;
|
|
|
|
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) {
|
|
filter['_id'] = username;
|
|
}
|
|
const uri = (typeof req.query.uri === 'string' ? req.queru.uri : null);
|
|
if (uri) {
|
|
filter['$or'] = [
|
|
{
|
|
'ownedBoards': uri
|
|
},
|
|
{
|
|
'modBoards': uri
|
|
},
|
|
];
|
|
}
|
|
|
|
let accounts, maxPage;
|
|
try {
|
|
[accounts, maxPage] = await Promise.all([
|
|
Accounts.find(filter, offset, limit),
|
|
Accounts.count(filter),
|
|
]);
|
|
maxPage = Math.ceil(maxPage/limit);
|
|
} catch (err) {
|
|
return next(err)
|
|
}
|
|
|
|
res
|
|
.set('Cache-Control', 'private, max-age=5')
|
|
.render('globalmanageaccounts', {
|
|
csrf: req.csrfToken(),
|
|
queryString,
|
|
username,
|
|
uri,
|
|
accounts,
|
|
page,
|
|
maxPage,
|
|
});
|
|
|
|
}
|
|
|