2017-08-02 17:13:02 -07:00
|
|
|
const errorHandlers = require('../helpers/errorHandlers.js');
|
2017-10-27 09:59:31 -07:00
|
|
|
const { getTrendingClaims, getRecentClaims } = require('../controllers/statsController.js');
|
2017-12-14 12:32:20 -08:00
|
|
|
const { site } = require('../config/speechConfig.js');
|
2017-06-29 17:10:14 -07:00
|
|
|
|
2017-06-27 20:25:36 -07:00
|
|
|
module.exports = (app) => {
|
2017-09-19 08:47:24 -07:00
|
|
|
// route to log out
|
|
|
|
app.get('/logout', (req, res) => {
|
|
|
|
req.logout();
|
2017-09-20 16:04:58 -07:00
|
|
|
res.redirect('/');
|
2017-09-19 08:47:24 -07:00
|
|
|
});
|
2017-09-16 17:50:22 -07:00
|
|
|
// route to display login page
|
|
|
|
app.get('/login', (req, res) => {
|
2018-01-30 09:00:02 -08:00
|
|
|
res.status(200).render('index');
|
2017-09-16 17:50:22 -07:00
|
|
|
});
|
2017-12-14 12:32:20 -08:00
|
|
|
// route to show 'about' page
|
2017-09-07 12:36:03 -07:00
|
|
|
app.get('/about', (req, res) => {
|
2018-01-29 12:34:34 -08:00
|
|
|
res.status(200).render('index');
|
2017-07-03 11:16:51 -07:00
|
|
|
});
|
2017-07-10 17:51:29 -07:00
|
|
|
// route to display a list of the trending images
|
2017-09-07 12:40:35 -07:00
|
|
|
app.get('/trending', (req, res) => {
|
|
|
|
res.status(301).redirect('/popular');
|
|
|
|
});
|
2017-11-02 11:50:05 -07:00
|
|
|
app.get('/popular', ({ ip, originalUrl }, res) => {
|
2017-07-10 17:51:29 -07:00
|
|
|
const startDate = new Date();
|
|
|
|
startDate.setDate(startDate.getDate() - 1);
|
2017-09-07 12:36:03 -07:00
|
|
|
const dateTime = startDate.toISOString().slice(0, 19).replace('T', ' ');
|
|
|
|
getTrendingClaims(dateTime)
|
2017-07-10 17:51:29 -07:00
|
|
|
.then(result => {
|
2017-09-29 14:11:00 -07:00
|
|
|
res.status(200).render('popular', {
|
2017-09-19 08:47:24 -07:00
|
|
|
trendingAssets: result,
|
|
|
|
});
|
2017-06-20 17:39:41 -07:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2017-12-06 18:49:05 -08:00
|
|
|
errorHandlers.handleRequestError(originalUrl, ip, error, res);
|
2017-06-20 17:39:41 -07:00
|
|
|
});
|
2017-06-19 22:37:36 -07:00
|
|
|
});
|
2017-08-24 16:09:04 -07:00
|
|
|
// route to display a list of the trending images
|
2017-11-02 11:50:05 -07:00
|
|
|
app.get('/new', ({ ip, originalUrl }, res) => {
|
2017-09-07 12:36:03 -07:00
|
|
|
getRecentClaims()
|
2017-08-24 16:09:04 -07:00
|
|
|
.then(result => {
|
2017-11-02 11:50:05 -07:00
|
|
|
res.status(200).render('new', { newClaims: result });
|
2017-08-24 16:09:04 -07:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2017-12-06 18:49:05 -08:00
|
|
|
errorHandlers.handleRequestError(originalUrl, ip, error, res);
|
2017-08-24 16:09:04 -07:00
|
|
|
});
|
|
|
|
});
|
2017-09-11 09:07:00 -07:00
|
|
|
// route to send embedable video player (for twitter)
|
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;
|
2017-12-14 12:32:20 -08:00
|
|
|
const host = site.host;
|
2017-08-07 17:08:03 -07:00
|
|
|
// get and render the content
|
2017-12-14 12:32:20 -08:00
|
|
|
res.status(200).render('embed', { layout: 'embed', host, claimId, name });
|
2017-08-07 17:08:03 -07:00
|
|
|
});
|
|
|
|
// route to display all free public claims at a given name
|
2017-09-19 08:47:24 -07:00
|
|
|
app.get('/:name/all', (req, res) => {
|
2017-06-29 17:10:14 -07:00
|
|
|
// get and render the content
|
2017-09-19 08:47:24 -07:00
|
|
|
res.status(410).send('/:name/all is no longer supported');
|
2017-06-19 18:37:35 +02:00
|
|
|
});
|
|
|
|
};
|