diff --git a/controllers/statsController.js b/controllers/statsController.js index 0b6d7666..98f954c6 100644 --- a/controllers/statsController.js +++ b/controllers/statsController.js @@ -156,4 +156,18 @@ module.exports = { }); }); }, + getRecentClaims (startDate) { + logger.debug('retrieving most recent claims'); + return new Promise((resolve, reject) => { + // get the raw requests data + db.sequelize.query(`SELECT * FROM File WHERE nsfw != 1 AND trendingEligible = 1 ORDER BY createdAt DESC LIMIT 25;`, { type: db.sequelize.QueryTypes.SELECT }) + .then(results => { + resolve(results); + }) + .catch(error => { + logger.error('sequelize error', error); + reject(error); + }); + }); + }, }; diff --git a/routes/page-routes.js b/routes/page-routes.js index c94b1472..b4189bd6 100644 --- a/routes/page-routes.js +++ b/routes/page-routes.js @@ -1,6 +1,6 @@ const errorHandlers = require('../helpers/errorHandlers.js'); const { getAllFreeClaims } = require('../helpers/serveHelpers.js'); -const { postToStats, getStatsSummary, getTrendingClaims } = require('../controllers/statsController.js'); +const { postToStats, getStatsSummary, getTrendingClaims, getRecentClaims } = require('../controllers/statsController.js'); module.exports = (app) => { // route to show 'about' page for spee.ch @@ -9,7 +9,7 @@ module.exports = (app) => { res.status(200).render('about'); }); // route to display a list of the trending images - app.get('/trending', ({ params, headers }, res) => { + app.get('/popular', ({ params, headers }, res) => { const startDate = new Date(); startDate.setDate(startDate.getDate() - 1); getTrendingClaims(startDate) @@ -21,6 +21,19 @@ module.exports = (app) => { errorHandlers.handleRequestError(error, res); }); }); + // route to display a list of the trending images + app.get('/new', ({ params, headers }, res) => { + const startDate = new Date(); + startDate.setDate(startDate.getDate() - 1); + getRecentClaims(startDate) + .then(result => { + // logger.debug(result); + res.status(200).render('new', { newClaims: result }); + }) + .catch(error => { + errorHandlers.handleRequestError(error, res); + }); + }); // route to show statistics for spee.ch app.get('/stats', ({ ip, originalUrl }, res) => { // get and render the content diff --git a/views/new.handlebars b/views/new.handlebars new file mode 100644 index 00000000..8b6cbbfb --- /dev/null +++ b/views/new.handlebars @@ -0,0 +1,26 @@ +
The 25 most recent publishes on spee.ch
+ {{#each newClaims}} +