2017-08-02 17:13:02 -07:00
|
|
|
const errorHandlers = require('../helpers/errorHandlers.js');
|
2017-08-15 15:35:03 -07:00
|
|
|
const { getAllFreeClaims } = require('../helpers/serveHelpers.js');
|
2017-07-10 17:51:29 -07:00
|
|
|
const { postToStats, getStatsSummary, getTrendingClaims } = require('../controllers/statsController.js');
|
2017-06-29 17:10:14 -07:00
|
|
|
|
2017-06-27 20:25:36 -07:00
|
|
|
module.exports = (app) => {
|
2017-07-03 11:16:51 -07:00
|
|
|
// route to show 'about' page for spee.ch
|
|
|
|
app.get('/about', ({ ip, originalUrl }, res) => {
|
|
|
|
// get and render the content
|
|
|
|
res.status(200).render('about');
|
|
|
|
});
|
2017-07-10 17:51:29 -07:00
|
|
|
// route to display a list of the trending images
|
|
|
|
app.get('/trending', ({ params, headers }, res) => {
|
|
|
|
const startDate = new Date();
|
|
|
|
startDate.setDate(startDate.getDate() - 1);
|
|
|
|
getTrendingClaims(startDate)
|
|
|
|
.then(result => {
|
2017-07-21 13:40:01 -07:00
|
|
|
// logger.debug(result);
|
2017-07-10 17:51:29 -07:00
|
|
|
res.status(200).render('trending', { trendingAssets: result });
|
2017-06-20 17:39:41 -07:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2017-07-10 17:51:29 -07:00
|
|
|
errorHandlers.handleRequestError(error, res);
|
2017-06-20 17:39:41 -07:00
|
|
|
});
|
2017-06-19 22:37:36 -07:00
|
|
|
});
|
2017-06-29 14:34:23 -07:00
|
|
|
// route to show statistics for spee.ch
|
2017-06-29 17:10:14 -07:00
|
|
|
app.get('/stats', ({ ip, originalUrl }, res) => {
|
|
|
|
// get and render the content
|
2017-07-10 17:51:29 -07:00
|
|
|
const startDate = new Date();
|
|
|
|
startDate.setDate(startDate.getDate() - 1);
|
|
|
|
getStatsSummary(startDate)
|
2017-06-29 14:34:23 -07:00
|
|
|
.then(result => {
|
2017-07-12 15:30:31 -07:00
|
|
|
postToStats('show', originalUrl, ip, null, null, 'success');
|
2017-06-29 14:34:23 -07: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 13:05:29 -07:00
|
|
|
app.get('/embed/:claimId/:name', ({ params }, res) => {
|
|
|
|
const claimId = params.claimId;
|
2017-08-08 13:22:03 -07:00
|
|
|
const name = params.name;
|
|
|
|
const dummyParam = '.b';
|
2017-08-08 13:05:29 -07:00
|
|
|
console.log('claimId ==', claimId);
|
|
|
|
console.log('name ==', name);
|
2017-08-07 17:08:03 -07:00
|
|
|
// get and render the content
|
2017-08-08 13:05:29 -07:00
|
|
|
res.status(200).render('embed', { layout: 'embed', claimId, name, dummyParam });
|
2017-08-07 17:08:03 -07:00
|
|
|
});
|
|
|
|
// route to display all free public claims at a given name
|
2017-06-29 17:10:14 -07:00
|
|
|
app.get('/:name/all', ({ ip, originalUrl, params }, res) => {
|
|
|
|
// get and render the content
|
2017-08-15 15:35:03 -07:00
|
|
|
getAllFreeClaims(params.name)
|
|
|
|
.then(orderedFreeClaims => {
|
|
|
|
if (!orderedFreeClaims) {
|
2017-06-30 15:31:23 -07:00
|
|
|
res.status(307).render('noClaims');
|
|
|
|
return;
|
|
|
|
}
|
2017-07-12 15:30:31 -07:00
|
|
|
postToStats('show', originalUrl, ip, null, null, 'success');
|
2017-08-15 15:35:03 -07:00
|
|
|
res.status(200).render('allClaims', { claims: orderedFreeClaims });
|
2017-06-17 22:51:30 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2017-06-27 22:41:48 -07:00
|
|
|
errorHandlers.handleRequestError('show', originalUrl, ip, error, res);
|
2017-06-19 18:37:35 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|