mirror of
https://github.com/Foltik/Shimapan
synced 2025-01-06 00:08:25 -05:00
Add raw document stats endpoints
This commit is contained in:
parent
cfcafdb993
commit
e2985de01d
@ -42,6 +42,83 @@ function mergeAggregations(res1, res2) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const uploadProps = [
|
||||||
|
{name: 'after', type: 'date', optional: true},
|
||||||
|
{name: 'before', type: 'date', optional: true},
|
||||||
|
{name: 'limit', type: 'number', min: 1, max: 10000, optional: true}
|
||||||
|
];
|
||||||
|
router.get('/uploads', requireAuth('stats.get'), bodyVerifier(uploadProps), wrap(async (req, res) => {
|
||||||
|
let constraints = {uploader: req.username};
|
||||||
|
|
||||||
|
// Set date constraints if specified
|
||||||
|
if (req.body.after || req.body.before)
|
||||||
|
constraints.date = {};
|
||||||
|
if (req.body.after)
|
||||||
|
constraints.date.$gt = new Date(req.body.after);
|
||||||
|
if (req.body.before)
|
||||||
|
constraints.date.$lt = new Date(req.body.before);
|
||||||
|
|
||||||
|
// Create query
|
||||||
|
const query = Upload.find(constraints);
|
||||||
|
|
||||||
|
// Limit if specified
|
||||||
|
if (req.body.limit)
|
||||||
|
query.limit(req.body.limit);
|
||||||
|
|
||||||
|
// Fetch and transform results
|
||||||
|
let uploads = await query;
|
||||||
|
uploads = uploads.map(upload => {
|
||||||
|
return {
|
||||||
|
date: upload.date,
|
||||||
|
uid: upload.uid,
|
||||||
|
key: upload.uploaderKey,
|
||||||
|
file: {
|
||||||
|
originalName: upload.file.originalName,
|
||||||
|
size: upload.file.size,
|
||||||
|
mime: upload.file.mime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(200).json(uploads);
|
||||||
|
}));
|
||||||
|
|
||||||
|
const viewProps = [
|
||||||
|
{name: 'after', type: 'date', optional: true},
|
||||||
|
{name: 'before', type: 'date', optional: true},
|
||||||
|
{name: 'limit', type: 'number', min: 1, max: 10000, optional: true}
|
||||||
|
];
|
||||||
|
router.get('/views', requireAuth('stats.get'), bodyVerifier(viewProps), wrap(async (req, res) => {
|
||||||
|
let constraints = {uploader: req.username};
|
||||||
|
|
||||||
|
// Set date constraints if specified
|
||||||
|
if (req.body.after || req.body.before)
|
||||||
|
constraints.date = {};
|
||||||
|
if (req.body.after)
|
||||||
|
constraints.date.$gt = new Date(req.body.after);
|
||||||
|
if (req.body.before)
|
||||||
|
constraints.date.$lt = new Date(req.body.before);
|
||||||
|
|
||||||
|
// Create query
|
||||||
|
const query = View.find(constraints);
|
||||||
|
|
||||||
|
// Limit if specified
|
||||||
|
if (req.body.limit)
|
||||||
|
query.limit(req.body.limit);
|
||||||
|
|
||||||
|
// Fetch and transform results
|
||||||
|
let views = await query;
|
||||||
|
views = views.map(view => {
|
||||||
|
return {
|
||||||
|
date: view.date,
|
||||||
|
uid: view.uid,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(200).json(views);
|
||||||
|
}));
|
||||||
|
|
||||||
router.get('/week', requireAuth('stats.get'), wrap(async (req, res) => {
|
router.get('/week', requireAuth('stats.get'), wrap(async (req, res) => {
|
||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user