spee.ch/routes/page-routes.js

81 lines
2.8 KiB
JavaScript
Raw Normal View History

2017-08-03 02:13:02 +02:00
const errorHandlers = require('../helpers/errorHandlers.js');
const db = require('../models');
2017-08-25 01:09:04 +02:00
const { postToStats, getStatsSummary, getTrendingClaims, getRecentClaims } = require('../controllers/statsController.js');
2017-06-30 02:10:14 +02:00
module.exports = (app) => {
2017-07-03 20:16:51 +02:00
// route to show 'about' page for spee.ch
app.get('/about', (req, res) => {
2017-07-03 20:16:51 +02:00
// get and render the content
res.status(200).render('about');
});
// route to display a list of the trending images
2017-09-07 21:40:35 +02:00
app.get('/trending', (req, res) => {
res.status(301).redirect('/popular');
});
app.get('/popular', (req, res) => {
const startDate = new Date();
startDate.setDate(startDate.getDate() - 1);
const dateTime = startDate.toISOString().slice(0, 19).replace('T', ' ');
getTrendingClaims(dateTime)
.then(result => {
// logger.debug(result);
res.status(200).render('trending', { trendingAssets: result });
2017-06-21 02:39:41 +02:00
})
.catch(error => {
errorHandlers.handleRequestError(error, res);
2017-06-21 02:39:41 +02:00
});
2017-06-20 07:37:36 +02:00
});
2017-08-25 01:09:04 +02:00
// route to display a list of the trending images
app.get('/new', (req, res) => {
getRecentClaims()
2017-08-25 01:09:04 +02:00
.then(result => {
// logger.debug(result);
res.status(200).render('new', { newClaims: result });
})
.catch(error => {
errorHandlers.handleRequestError(error, res);
});
});
2017-06-29 23:34:23 +02:00
// route to show statistics for spee.ch
2017-06-30 02:10:14 +02:00
app.get('/stats', ({ ip, originalUrl }, res) => {
// get and render the content
const startDate = new Date();
startDate.setDate(startDate.getDate() - 1);
getStatsSummary(startDate)
2017-06-29 23:34:23 +02:00
.then(result => {
2017-07-13 00:30:31 +02:00
postToStats('show', originalUrl, ip, null, null, 'success');
2017-06-29 23:34:23 +02:00
res.status(200).render('statistics', result);
})
.catch(error => {
errorHandlers.handleRequestError(error, res);
});
});
// route to display all free public claims at a given name
2017-08-08 22:05:29 +02:00
app.get('/embed/:claimId/:name', ({ params }, res) => {
const claimId = params.claimId;
2017-08-08 22:22:03 +02:00
const name = params.name;
const dummyParam = '.b';
2017-08-08 22:05:29 +02:00
console.log('claimId ==', claimId);
console.log('name ==', name);
2017-08-08 02:08:03 +02:00
// get and render the content
2017-08-08 22:05:29 +02:00
res.status(200).render('embed', { layout: 'embed', claimId, name, dummyParam });
2017-08-08 02:08:03 +02:00
});
// route to display all free public claims at a given name
2017-06-30 02:10:14 +02:00
app.get('/:name/all', ({ ip, originalUrl, params }, res) => {
// get and render the content
db
.getAllFreeClaims(params.name)
.then(orderedFreeClaims => {
if (!orderedFreeClaims) {
res.status(307).render('noClaims');
return;
}
2017-07-13 00:30:31 +02:00
postToStats('show', originalUrl, ip, null, null, 'success');
res.status(200).render('allClaims', { claims: orderedFreeClaims });
})
.catch(error => {
2017-06-28 07:41:48 +02:00
errorHandlers.handleRequestError('show', originalUrl, ip, error, res);
});
});
};