mirror of
https://codeberg.org/tacerus/teddit.git
synced 2024-11-22 06:49:26 +01:00
separate search route
This commit is contained in:
parent
74c202d5f0
commit
c0e20b5817
@ -2,6 +2,7 @@ const homeRoute = require('./home');
|
||||
const overridingRoutes = require('./overides');
|
||||
const preferenceRoutes = require('./preferences');
|
||||
const saveRoutes = require('./save');
|
||||
const searchRoute = require('./search');
|
||||
const staticRoutes = require('./static');
|
||||
const subredditRoutes = require('./subreddit');
|
||||
const subscriptionRoutes = require('./subscription');
|
||||
@ -16,6 +17,7 @@ allRoutes.use(subredditRoutes);
|
||||
allRoutes.use(userRoutes);
|
||||
allRoutes.use(subscriptionRoutes);
|
||||
allRoutes.use(saveRoutes);
|
||||
allRoutes.use(searchRoute);
|
||||
allRoutes.use(homeRoute);
|
||||
|
||||
module.exports = allRoutes;
|
||||
|
48
routes/search.js
Normal file
48
routes/search.js
Normal file
@ -0,0 +1,48 @@
|
||||
const searchRoute = require('express').Router();
|
||||
|
||||
searchRoute.get('/search', (req, res, next) => {
|
||||
let q = req.query.q;
|
||||
|
||||
if (typeof q === 'undefined') {
|
||||
return res.render('search', {
|
||||
json: { posts: [] },
|
||||
no_query: true,
|
||||
q: '',
|
||||
restrict_sr: undefined,
|
||||
nsfw: undefined,
|
||||
subreddit: 'all',
|
||||
sortby: undefined,
|
||||
past: undefined,
|
||||
user_preferences: req.cookies,
|
||||
});
|
||||
}
|
||||
|
||||
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}`
|
||||
);
|
||||
});
|
||||
|
||||
module.exports = searchRoute;
|
Loading…
Reference in New Issue
Block a user