From 7c7709e74fb25f5ffb2d3d2755c32892ade63579 Mon Sep 17 00:00:00 2001 From: teddit Date: Sun, 30 Jan 2022 01:33:58 +0100 Subject: [PATCH] improve subreddit search, include sort and t params (#204) --- routes/subreddit.js | 9 +++++++-- views/search.pug | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/routes/subreddit.js b/routes/subreddit.js index 25e685d..e220322 100644 --- a/routes/subreddit.js +++ b/routes/subreddit.js @@ -55,6 +55,11 @@ subredditRoutes.get('/r/:subreddit/search', (req, res, next) => { if (nsfw !== 'on') { nsfw = 'off'; } + + let count = '&count=25'; + if (after == '') { + count = ''; + } let key = `search:${subreddit}:${q}:${restrict_sr}:${sortby}:${past}:${after}:${before}:${nsfw}`; redis.get(key, (error, json) => { @@ -90,9 +95,9 @@ subredditRoutes.get('/r/:subreddit/search', (req, res, next) => { } else { let url = ''; if (config.use_reddit_oauth) - url = `https://oauth.reddit.com/r/${subreddit}/search?api_type=json&q=${q}&restrict_sr=${restrict_sr}&include_over_18=${nsfw}&sort=${sortby}&t=${past}${d}`; + url = `https://oauth.reddit.com/r/${subreddit}/search?api_type=json&q=${q}&restrict_sr=${restrict_sr}&include_over_18=${nsfw}&sort=${sortby}&t=${past}${count}${d}`; else - url = `https://reddit.com/r/${subreddit}/search.json?api_type=json&q=${q}&restrict_sr=${restrict_sr}&include_over_18=${nsfw}&sort=${sortby}&t=${past}${d}`; + url = `https://reddit.com/r/${subreddit}/search.json?api_type=json&q=${q}&restrict_sr=${restrict_sr}&include_over_18=${nsfw}&sort=${sortby}&t=${past}${count}${d}`; fetch(encodeURI(url), redditApiGETHeaders()) .then((result) => { if (result.status === 200) { diff --git a/views/search.pug b/views/search.pug index 666658f..8957a4f 100644 --- a/views/search.pug +++ b/views/search.pug @@ -140,8 +140,8 @@ html include components/link.pug if json.before || json.after .view-more-links - if json.before && !subreddit_front - a(href="?q=" + q + "&restrict_sr=" + restrict_sr + "&nsfw=" + nsfw + "&before=" + json.before + "") ‹ prev + if json.before + a(href="?q=" + q + "&restrict_sr=" + restrict_sr + "&nsfw=" + nsfw + "&before=" + json.before + "" + (sortby === "new" && sortby ? "&" : "&sort=" + sortby + "&") + (!past ? "" : "t=" + past)) ‹ prev if json.after - a(href="?q=" + q + "&restrict_sr=" + restrict_sr + "&nsfw=" + nsfw + "&after=" + json.after + "") next › + a(href="?q=" + q + "&restrict_sr=" + restrict_sr + "&nsfw=" + nsfw + "&after=" + json.after + "" + (sortby === "new" && sortby ? "&" : "&sort=" + sortby + "&") + (!past ? "" : "t=" + past)) next › include includes/footer.pug