Only send get_comments requests if comments are enabled

This commit is contained in:
metalune 2021-01-21 10:30:26 +01:00
parent 8be6ab231c
commit 0e44673dc6
2 changed files with 36 additions and 26 deletions

View file

@ -28,6 +28,7 @@ class VideoWrapper:
self.dislikes = a["dislikes"] self.dislikes = a["dislikes"]
self.embedPath = a["embedPath"] self.embedPath = a["embedPath"]
self.commentsEnabled = a["commentsEnabled"]
self.resolutions = [] self.resolutions = []
self.video = None self.video = None
@ -92,11 +93,16 @@ async def video(domain, id):
quality = "best" quality = "best"
vid = VideoWrapper(data, quality) vid = VideoWrapper(data, quality)
# only make a request for the comments if commentsEnabled
comments = ""
if data["commentsEnabled"]:
comments = peertube.get_comments(domain, id)
return await render_template( return await render_template(
"video.html", "video.html",
domain=domain, domain=domain,
video=vid, video=vid,
comments=peertube.get_comments(domain, id), comments=comments,
quality=quality, quality=quality,
embed=embed, embed=embed,
commit=commit, commit=commit,

View file

@ -65,32 +65,36 @@ Views: <b>{{ video.views }}</b> Likes: <b>{{ video.likes }}</b> Dislikes: <b>{{
<br> <br>
<br> <br>
<br> <br>
{{ comments.total }} Comments {% if video.commentsEnabled %}
<br> {{ comments.total }} Comments
<br> <br>
{% for comment in comments.data %} <br>
{% for comment in comments.data %}
{% if not comment.isDeleted %} {% if not comment.isDeleted %}
<b>{{ comment.account.displayName }}</b> <b>{{ comment.account.displayName }}</b>
<br>
{{ comment.text }}
<br>
{% else %}
<div style="color: #5F5F5F">
<b>Unknown</b>
<br> <br>
Deleted Comment {{ comment.text }}
</div> <br>
{% endif %} {% else %}
<i> <div style="color: #5F5F5F">
{% if comment.totalReplies == 1 %} <b>Unknown</b>
1 Reply <br>
{% else %} Deleted Comment
{{ comment.totalReplies }} Replies </div>
{% endif %} {% endif %}
</i> <i>
<br> {% if comment.totalReplies == 1 %}
<br> 1 Reply
{% endfor %} {% else %}
{{ comment.totalReplies }} Replies
{% endif %}
</i>
<br>
<br>
{% endfor %}
{% else %}
Comments disabled.
{% endif %}
{% endblock %} {% endblock %}