/stats?all=true

This commit is contained in:
Klemek
2021-04-06 09:58:51 +02:00
parent c3e53c7df8
commit 8a9b9cdcfe
4 changed files with 133 additions and 62 deletions
+19 -3
View File
@@ -201,9 +201,25 @@ module.exports = (config) => {
});
app.get('/stats', (req, res) => {
if (config['modules']['hit_counter']) {
hc.read('/', (data) => {
res.json(data);
});
if (req.query['all']) {
const keys = Object.keys(articles).filter(key => !articles[key].draft);
keys.unshift('/');
const read = (i, outputData) => {
if (i >= keys.length) {
res.json(outputData);
} else {
hc.read(keys[i], (data) => {
outputData.push(data);
read(i + 1, outputData);
});
}
};
read(0, []);
} else {
hc.read('/', (data) => {
res.json(data);
});
}
} else {
showError(req, res, 404);
}