diff --git a/routes.js b/routes.js index 28de1dd..6504f8e 100644 --- a/routes.js +++ b/routes.js @@ -9,6 +9,51 @@ module.exports = (app, redis, fetch, RedditAPI) => { let processSearches = require('./inc/processSearchResults.js')(); let processSidebar = require('./inc/processSubredditSidebar.js')(); + app.get('/about', (req, res, next) => { + return res.render('about', { user_preferences: req.cookies }) + }) + + app.get('/preferences', (req, res, next) => { + return res.render('preferences', { user_preferences: req.cookies }) + }) + + app.get('/resetprefs', (req, res, next) => { + res.clearCookie('theme') + return res.redirect('/preferences') + }) + + app.get('/privacy', (req, res, next) => { + return res.render('privacypolicy', { user_preferences: req.cookies }) + }) + + app.get('/search', (req, res, next) => { + let q = req.query.q + let restrict_sr = req.query.restrict_sr + let nsfw = req.query.nsfw + let sortby = req.query.sort + let past = req.query.t + let after = req.query.after + let before = req.query.before + if(!after) { + after = '' + } + if(!before) { + before = '' + } + if(restrict_sr !== 'on') { + restrict_sr = 'off' + } + + if(nsfw !== 'on') { + nsfw = 'off' + } + let d = `&after=${after}` + if(before) { + d = `&before=${before}` + } + return res.redirect(`/r/all/search?q=${q}&restrict_sr=${restrict_sr}&nsfw=${nsfw}&sort=${sortby}&t=${past}${d}`) + }) + app.get('/:sort?', (req, res, next) => { let past = req.query.t let before = req.query.before @@ -100,51 +145,6 @@ module.exports = (app, redis, fetch, RedditAPI) => { }) }) - app.get('/about', (req, res, next) => { - return res.render('about', { user_preferences: req.cookies }) - }) - - app.get('/preferences', (req, res, next) => { - return res.render('preferences', { user_preferences: req.cookies }) - }) - - app.get('/resetprefs', (req, res, next) => { - res.clearCookie('theme') - return res.redirect('/preferences') - }) - - app.get('/privacy', (req, res, next) => { - return res.render('privacypolicy', { user_preferences: req.cookies }) - }) - - app.get('/search', (req, res, next) => { - let q = req.query.q - let restrict_sr = req.query.restrict_sr - let nsfw = req.query.nsfw - let sortby = req.query.sort - let past = req.query.t - let after = req.query.after - let before = req.query.before - if(!after) { - after = '' - } - if(!before) { - before = '' - } - if(restrict_sr !== 'on') { - restrict_sr = 'off' - } - - if(nsfw !== 'on') { - nsfw = 'off' - } - let d = `&after=${after}` - if(before) { - d = `&before=${before}` - } - return res.redirect(`/r/all/search?q=${q}&restrict_sr=${restrict_sr}&nsfw=${nsfw}&sort=${sortby}&t=${past}${d}`) - }) - app.get('/comments/:post_id/:comment?/:comment_id?', (req, res, next) => { let post_id = req.params.post_id let comment = req.params.comment