mirror of
https://codeberg.org/tacerus/teddit.git
synced 2024-11-28 18:49:23 +01:00
49 lines
1.0 KiB
JavaScript
49 lines
1.0 KiB
JavaScript
|
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;
|