diff --git a/files/helpers/regex.py b/files/helpers/regex.py index 39a4d0a45..7eb1085f6 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -279,6 +279,8 @@ reddit_s_url_regex = re.compile("https:\/\/reddit.com\/[ru]\/\w{2,25}\/s\/\w{10} #run-time reddit_to_vreddit_regex = re.compile('(^|>|")https:\/\/old.reddit.com\/(r|user)\/', flags=re.A) +#post search +subreddit_name_regex = re.compile('\w{2,25}', flags=re.A) ###YOUTUBE diff --git a/files/routes/search.py b/files/routes/search.py index 769481279..3dd4dd115 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -22,6 +22,7 @@ valid_params = [ 'title', 'sentto', search_operator_hole, + 'subreddit', ] def searchparse(text): @@ -129,6 +130,15 @@ def searchposts(v): ) ) + if 'subreddit' in criteria: + subreddit = criteria['subreddit'] + + if not subreddit_name_regex.fullmatch(subreddit): + abort(400, "Invalid subreddit name.") + + posts = posts.filter(Post.url.ilike(f"https://old.reddit.com/r/{subreddit}/%")) + + if search_operator_hole in criteria: posts = posts.filter(Post.sub == criteria[search_operator_hole]) diff --git a/files/templates/search.html b/files/templates/search.html index ee0540fbf..67d68e302 100644 --- a/files/templates/search.html +++ b/files/templates/search.html @@ -77,6 +77,10 @@
Exact Match Only:
+
+
Subreddit:
+ +
{% endif %} {% if FEATURES['NSFW_MARKING'] %}