From a23aa0bb82254076b4b1e60c56cc59285a1068fc Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 24 Aug 2017 16:09:04 -0700 Subject: [PATCH] updated new and trending pages --- controllers/statsController.js | 14 ++++++++++++ routes/page-routes.js | 17 +++++++++++++-- views/new.handlebars | 26 +++++++++++++++++++++++ views/partials/topBar.handlebars | 3 ++- views/partials/trendingAssets.handlebars | 27 +++++++++++++----------- 5 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 views/new.handlebars 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 @@ +
+ {{> topBar}} +
+

New on Spee.ch

+

The 25 most recent publishes on spee.ch

+ {{#each newClaims}} + + {{/each}} +
+ {{> footer}} +
\ No newline at end of file diff --git a/views/partials/topBar.handlebars b/views/partials/topBar.handlebars index 0f424b12..8251ee1d 100644 --- a/views/partials/topBar.handlebars +++ b/views/partials/topBar.handlebars @@ -1,7 +1,8 @@

Spee.ch

(beta) - trending + new + popular source help
Open-source, decentralized image and video hosting.
diff --git a/views/partials/trendingAssets.handlebars b/views/partials/trendingAssets.handlebars index 599d671d..90e6d4d1 100644 --- a/views/partials/trendingAssets.handlebars +++ b/views/partials/trendingAssets.handlebars @@ -2,22 +2,25 @@

Trending

+

The 25 most popular assets on spee.ch