2016-05-24 22:01:46 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
2020-05-15 15:29:28 -04:00
|
|
|
const json2csvAsync = require('json2csv').parseAsync;
|
2016-05-24 22:01:46 -04:00
|
|
|
|
2019-08-14 16:27:58 -04:00
|
|
|
const meta = require('../../meta');
|
|
|
|
|
const analytics = require('../../analytics');
|
|
|
|
|
const utils = require('../../utils');
|
2016-05-24 22:01:46 -04:00
|
|
|
|
2019-08-14 16:27:58 -04:00
|
|
|
const errorsController = module.exports;
|
2016-05-24 22:01:46 -04:00
|
|
|
|
2019-08-14 16:27:58 -04:00
|
|
|
errorsController.get = async function (req, res) {
|
|
|
|
|
const data = await utils.promiseParallel({
|
|
|
|
|
'not-found': meta.errors.get(true),
|
|
|
|
|
analytics: analytics.getErrorAnalytics(),
|
|
|
|
|
});
|
|
|
|
|
res.render('admin/advanced/errors', data);
|
2016-05-24 22:01:46 -04:00
|
|
|
};
|
|
|
|
|
|
2019-08-14 16:27:58 -04:00
|
|
|
errorsController.export = async function (req, res) {
|
|
|
|
|
const data = await meta.errors.get(false);
|
2020-05-15 15:29:28 -04:00
|
|
|
const fields = data.length ? Object.keys(data[0]) : [];
|
|
|
|
|
const opts = { fields };
|
|
|
|
|
const csv = await json2csvAsync(data, opts);
|
2019-08-14 16:27:58 -04:00
|
|
|
res.set('Content-Type', 'text/csv').set('Content-Disposition', 'attachment; filename="404.csv"').send(csv);
|
2016-05-24 23:04:57 -04:00
|
|
|
};
|