Skip to content

Commit

Permalink
[DONE] Use get_thumbnail to serve video thumbnail via caching system (E…
Browse files Browse the repository at this point in the history
…supPortail#1221)

Prevents video thumbnail url to be publicly available, and serve it via cache system
  • Loading branch information
Badatos authored Oct 29, 2024
1 parent e1cad6f commit 39b25f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
42 changes: 22 additions & 20 deletions pod/main/templates/block/carousel.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,28 @@ <h2>{{ title |capfirst|truncatechars:43 }}</h2>
{% endif %}
<a href="{{ element.get_absolute_url }}" title="{{ element.title }}">
{% if type == "video" or type == 'last' %}
<img
src="{{ element.get_thumbnail_url }}"
class="img-fluid d-block w-100"
alt=""/>
{% elif type == "event" %} {% if element.thumbnail %}
<img
src="{{ element.get_thumbnail_card }}"
class="img-fluid d-block w-100"
alt=""/>
{% elif element.broadcaster.poster %}
<img
src="{{ element.broadcaster.get_poster_url }}"
class="img-fluid d-block w-100"
alt=""/>
{% else %}
<img
src="{{ element.get_thumbnail_card }}"
class="img-fluid d-block w-100"
alt=""/>
{% endif %} {% endif %}
<img
src="{{ element.get_thumbnail_url }}"
class="img-fluid d-block w-100"
alt=""/>
{% elif type == "event" %}
{% if element.thumbnail %}
<img
src="{{ element.get_thumbnail_card }}"
class="img-fluid d-block w-100"
alt=""/>
{% elif element.broadcaster.poster %}
<img
src="{{ element.broadcaster.get_poster_url }}"
class="img-fluid d-block w-100"
alt=""/>
{% else %}
<img
src="{{ element.get_thumbnail_card }}"
class="img-fluid d-block w-100"
alt=""/>
{% endif %}
{% endif %}
<div class="carousel-caption d-none d-md-block">
<h3 class="video-title">
{{ element.title|capfirst|truncatechars:43 }}
Expand Down
13 changes: 4 additions & 9 deletions pod/video/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,22 +1005,17 @@ def get_thumbnail_url(self) -> str:
"""Get a thumbnail url for the video."""
request = None
if self.thumbnail and self.thumbnail.file_exist():
thumbnail_url = "".join(
[
"//",
get_current_site(request).domain,
self.thumbnail.file.url,
]
)
# Do not serve thumbnail url directly, as it can lead to the video URL
im = get_thumbnail(self.thumbnail.file, "x170", crop="center", quality=80)
return im.url
else:
thumbnail_url = "".join(
return "".join(
[
"//",
get_current_site(request).domain,
static(DEFAULT_THUMBNAIL),
]
)
return thumbnail_url

@property
def get_thumbnail_admin(self):
Expand Down

0 comments on commit 39b25f9

Please sign in to comment.