mirror of
https://gitlab.com/SIGBUS/nyaa.git
synced 2024-12-22 08:40:00 +00:00
search: allow limiting the maximum number of pages
This commit is contained in:
parent
2782589cda
commit
6608c99b90
|
@ -149,6 +149,9 @@ BACKUP_TORRENT_FOLDER = 'torrents'
|
||||||
# How many results should a page contain. Applies to RSS as well.
|
# How many results should a page contain. Applies to RSS as well.
|
||||||
RESULTS_PER_PAGE = 75
|
RESULTS_PER_PAGE = 75
|
||||||
|
|
||||||
|
# How many pages we'll return at most
|
||||||
|
MAX_PAGES = 100
|
||||||
|
|
||||||
# Use better searching with ElasticSearch
|
# Use better searching with ElasticSearch
|
||||||
# See README.MD on setup!
|
# See README.MD on setup!
|
||||||
USE_ELASTIC_SEARCH = False
|
USE_ELASTIC_SEARCH = False
|
||||||
|
|
|
@ -372,6 +372,12 @@ def search_db(term='', user=None, sort='id', order='desc', category='0_0',
|
||||||
if page > 4294967295:
|
if page > 4294967295:
|
||||||
flask.abort(404)
|
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 = {
|
sort_keys = {
|
||||||
'id': models.Torrent.id,
|
'id': models.Torrent.id,
|
||||||
'size': models.Torrent.filesize,
|
'size': models.Torrent.filesize,
|
||||||
|
@ -518,6 +524,7 @@ def search_db(term='', user=None, sort='id', order='desc', category='0_0',
|
||||||
if rss:
|
if rss:
|
||||||
query = query.limit(per_page)
|
query = query.limit(per_page)
|
||||||
else:
|
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
|
return query
|
||||||
|
|
Loading…
Reference in a new issue