improve subreddit search, include sort and t params (#204)
This commit is contained in:
parent
eac2627114
commit
7c7709e74f
|
@ -56,6 +56,11 @@ subredditRoutes.get('/r/:subreddit/search', (req, res, next) => {
|
||||||
nsfw = 'off';
|
nsfw = 'off';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let count = '&count=25';
|
||||||
|
if (after == '') {
|
||||||
|
count = '';
|
||||||
|
}
|
||||||
|
|
||||||
let key = `search:${subreddit}:${q}:${restrict_sr}:${sortby}:${past}:${after}:${before}:${nsfw}`;
|
let key = `search:${subreddit}:${q}:${restrict_sr}:${sortby}:${past}:${after}:${before}:${nsfw}`;
|
||||||
redis.get(key, (error, json) => {
|
redis.get(key, (error, json) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -90,9 +95,9 @@ subredditRoutes.get('/r/:subreddit/search', (req, res, next) => {
|
||||||
} else {
|
} else {
|
||||||
let url = '';
|
let url = '';
|
||||||
if (config.use_reddit_oauth)
|
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
|
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())
|
fetch(encodeURI(url), redditApiGETHeaders())
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
if (result.status === 200) {
|
if (result.status === 200) {
|
||||||
|
|
|
@ -140,8 +140,8 @@ html
|
||||||
include components/link.pug
|
include components/link.pug
|
||||||
if json.before || json.after
|
if json.before || json.after
|
||||||
.view-more-links
|
.view-more-links
|
||||||
if json.before && !subreddit_front
|
if json.before
|
||||||
a(href="?q=" + q + "&restrict_sr=" + restrict_sr + "&nsfw=" + nsfw + "&before=" + json.before + "") ‹ prev
|
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
|
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
|
include includes/footer.pug
|
||||||
|
|
Loading…
Reference in New Issue