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