aboutsummaryrefslogtreecommitdiff
path: root/src/api/routes
diff options
context:
space:
mode:
authorZephyrrus <[email protected]>2021-01-07 23:55:37 +0200
committerZephyrrus <[email protected]>2021-01-07 23:55:37 +0200
commit925080f6a08a1f1515143db1bd6aef8109f5fb67 (patch)
tree298476e0f2aea59422bcc46fb1e1ce8bb4f19c18 /src/api/routes
parentchore: revert nuxt update, it breaks SSR in development mode, not worth it. (diff)
downloadhost.fuwn.me-925080f6a08a1f1515143db1bd6aef8109f5fb67.tar.xz
host.fuwn.me-925080f6a08a1f1515143db1bd6aef8109f5fb67.zip
chore: refactor stats generator to use an enum for types
fix: saved data not being converted to JSON automatically when using SQLite (and possibly MSSQL) feat: display when a stat was generated in the section's header fix: not being able to click through the footer (sorry IE11 users, you still won't be able to click through it) fix: add is-mobile to columns so they don't stack on top of each other feat: add text next to the NSFW toggle and make it look like the elements around it (begone round iOS edges)
Diffstat (limited to 'src/api/routes')
-rw-r--r--src/api/routes/service/statsGET.js24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/api/routes/service/statsGET.js b/src/api/routes/service/statsGET.js
index d6fa69e..2241ca8 100644
--- a/src/api/routes/service/statsGET.js
+++ b/src/api/routes/service/statsGET.js
@@ -1,5 +1,6 @@
const Route = require('../../structures/Route');
const StatsGenerator = require('../../utils/StatsGenerator');
+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 {
@@ -9,12 +10,23 @@ class filesGET extends Route {
async run(req, res, db) {
const cachedStats = await db('statistics')
- .select('type', 'data', 'batchId')
+ .select('type', 'data', 'batchId', 'createdAt')
.where('batchId', '=', db('statistics').max('batchId'));
- let stats = cachedStats.reduce((acc, { type, data }) => {
+ let stats = cachedStats.reduce((acc, { type, data, createdAt }) => {
try {
- acc[type] = JSON.parse(data);
+ // pg returns json, sqlite retuns a string...
+ if (typeof data === 'string' || data instanceof String) {
+ acc[type] = JSON.parse(data);
+ } else {
+ acc[type] = data;
+ }
+
+ acc[type].meta = {
+ cached: true,
+ generatedOn: moment(createdAt).format('MMMM Do YYYY, h:mm:ss a z'), // pg returns this as a date, sqlite3 returns an unix timestamp :<
+ type: StatsGenerator.Type.HIDDEN
+ };
} catch (e) {
console.error(e);
}
@@ -24,10 +36,12 @@ class filesGET extends Route {
stats = { ...stats, ...(await StatsGenerator.getMissingStats(db, Object.keys(stats))) };
- return res.json(StatsGenerator.keyOrder.reduce((acc, k) => {
+ const ordered = StatsGenerator.keyOrder.reduce((acc, k) => {
acc[k] = stats[k];
return acc;
- }, {}));
+ }, {});
+
+ return res.json({ statistics: ordered });
}
}