1
0
Fork 0
mirror of https://gitlab.com/SIGBUS/nyaa.git synced 2024-12-21 16:30:00 +00:00

search: allow limiting the maximum number of pages

This commit is contained in:
Nicolas F 2019-04-02 17:28:39 +02:00 committed by Nicolas F
parent 2782589cda
commit 6608c99b90
2 changed files with 11 additions and 1 deletions

View file

@ -149,6 +149,9 @@ BACKUP_TORRENT_FOLDER = 'torrents'
# How many results should a page contain. Applies to RSS as well.
RESULTS_PER_PAGE = 75
# How many pages we'll return at most
MAX_PAGES = 100
# Use better searching with ElasticSearch
# See README.MD on setup!
USE_ELASTIC_SEARCH = False

View file

@ -372,6 +372,12 @@ def search_db(term='', user=None, sort='id', order='desc', category='0_0',
if page > 4294967295:
flask.abort(404)
MAX_PAGES = app.config.get("MAX_PAGES", 0)
if MAX_PAGES and page > MAX_PAGES:
flask.abort(flask.Response("You've exceeded the maximum number of pages. Please "
"make your search query less broad.", 403))
sort_keys = {
'id': models.Torrent.id,
'size': models.Torrent.filesize,
@ -518,6 +524,7 @@ def search_db(term='', user=None, sort='id', order='desc', category='0_0',
if rss:
query = query.limit(per_page)
else:
query = query.paginate_faste(page, per_page=per_page, step=5, count_query=count_query)
query = query.paginate_faste(page, per_page=per_page, step=5, count_query=count_query,
max_page=MAX_PAGES)
return query