Comments: Fix exceptions when ctoken metadata are missing (None)

Signed-off-by: Jesús <heckyel@hyperbola.info>
This commit is contained in:
James Taylor 2021-08-07 14:36:11 -07:00 committed by Jesús
parent 7720f3bde5
commit bee14ea9ea
No known key found for this signature in database
GPG Key ID: F6EE7BC59A315766
2 changed files with 14 additions and 3 deletions

View File

@ -143,7 +143,10 @@ def post_process_comments_info(comments_info):
comments_info['more_comments_url'] = concat_or_none(
util.URL_ORIGIN, '/comments?ctoken=', ctoken, replies_param)
comments_info['page_number'] = page_number = str(int(comments_info['offset']/20) + 1)
if comments_info['offset'] is None:
comments_info['page_number'] = None
else:
comments_info['page_number'] = int(comments_info['offset']/20) + 1
if not comments_info['is_replies']:
comments_info['sort_text'] = 'top' if comments_info['sort'] == 0 else 'newest'
@ -213,7 +216,15 @@ def get_comments_page():
post_process_comments_info(comments_info)
if not replies:
other_sort_url = util.URL_ORIGIN + '/comments?ctoken=' + make_comment_ctoken(comments_info['video_id'], sort=1 - comments_info['sort'])
if comments_info['sort'] is None or comments_info['video_id'] is None:
other_sort_url = None
else:
other_sort_url = (
util.URL_ORIGIN
+ '/comments?ctoken='
+ make_comment_ctoken(comments_info['video_id'],
sort=1-comments_info['sort'])
)
other_sort_text = 'Sort by ' + ('newest' if comments_info['sort'] == 0 else 'top')
comments_info['comment_links'] = [(other_sort_text, other_sort_url)]

View File

@ -1,4 +1,4 @@
{% set page_title = ('Replies' if comments_info['is_replies'] else 'Comments page ' + comments_info['page_number']) %}
{% set page_title = ('Replies' if comments_info['is_replies'] else 'Comments page ' + comments_info['page_number']|string) %}
{% import "comments.html" as comments with context %}
{% if not slim %}