aboutsummaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorPitu <[email protected]>2021-01-08 20:55:57 +0900
committerPitu <[email protected]>2021-01-08 20:55:57 +0900
commit523359ec32e3fc8a8ede1fd394d73ec311979583 (patch)
treeb4fa578b1ab461694d2205dc85e9270664444d0e /src/api
parentchore: force migration on service start (diff)
downloadhost.fuwn.me-523359ec32e3fc8a8ede1fd394d73ec311979583.tar.xz
host.fuwn.me-523359ec32e3fc8a8ede1fd394d73ec311979583.zip
chore: be able to refresh stats on demand
Diffstat (limited to 'src/api')
-rw-r--r--src/api/routes/service/statsGET.js19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/api/routes/service/statsGET.js b/src/api/routes/service/statsGET.js
index 2241ca8..6d5197b 100644
--- a/src/api/routes/service/statsGET.js
+++ b/src/api/routes/service/statsGET.js
@@ -5,10 +5,27 @@ const moment = require('moment');
// Thank you Bobby for the stats code https://github.com/BobbyWibowo/lolisafe/blob/safe.fiery.me/controllers/utilsController.js
class filesGET extends Route {
constructor() {
- super('/service/statistics', 'get', { adminOnly: true });
+ super('/service/statistics/:category?', 'get', { adminOnly: true });
}
async run(req, res, db) {
+ const { category } = req.params;
+ if (category) {
+ const dbRes = await StatsGenerator.statGenerators[category](db);
+ return res.json({
+ statistics: {
+ [category]: {
+ ...dbRes,
+ meta: {
+ cached: true,
+ generatedOn: moment().format('MMMM Do YYYY, h:mm:ss a z'), // pg returns this as a date, sqlite3 returns an unix timestamp :<
+ type: StatsGenerator.Type.HIDDEN
+ }
+ }
+ }
+ });
+ }
+
const cachedStats = await db('statistics')
.select('type', 'data', 'batchId', 'createdAt')
.where('batchId', '=', db('statistics').max('batchId'));