diff --git a/blueprints/tasks.py b/blueprints/tasks.py index d98542b..a521414 100644 --- a/blueprints/tasks.py +++ b/blueprints/tasks.py @@ -230,6 +230,17 @@ def task_cache_attachments() -> _Response: obj = activity.get_object() + if obj.has_type(ap.ActivityType.VIDEO): + if isinstance(obj.url, list): + for link in obj.url: + if link.get("mimeType", "").startswith("video/"): + config.MEDIA_CACHE.cache_attachment({"url": link["href"]}, iri) + break + elif isinstance(obj.url, str): + config.MEDIA_CACHE.cache_attachment({"url": obj.url}, iri) + else: + app.logger.warning(f"failed to parse video link {obj!r} for {iri}") + # Iter the attachments for attachment in obj._data.get("attachment", []): try: @@ -284,9 +295,12 @@ def task_cache_actor() -> _Response: # ) app.logger.info(f"actor cached for {iri}") - if activity.has_type( - [ap.ActivityType.CREATE, ap.ActivityType.ANNOUNCE] - ) and activity.get_object()._data.get("attachment", []): + if not activity.has_type([ap.ActivityType.CREATE, ap.ActivityType.ANNOUNCE]): + return "" + + if activity.get_object()._data.get( + "attachment", [] + ) or activity.get_object().has_type(ap.ActivityType.VIDEO): Tasks.cache_attachments(iri) except (ActivityGoneError, ActivityNotFoundError): diff --git a/templates/utils.html b/templates/utils.html index 057c395..edaa8f1 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -67,7 +67,7 @@ {% if obj.summary %}

{{ obj.summary | clean | safe }}

{% endif %} {% if obj | has_type('Video') %}
-
{% endif %} diff --git a/utils/template_filters.py b/utils/template_filters.py index 8978862..2f8b444 100644 --- a/utils/template_filters.py +++ b/utils/template_filters.py @@ -249,6 +249,11 @@ def get_attachment_url(url, size): return _get_file_url(url, size, Kind.ATTACHMENT) +@filters.app_template_filter() +def get_video_url(url): + return _get_file_url(url, None, Kind.ATTACHMENT) + + @filters.app_template_filter() def get_og_image_url(url, size=100): try: @@ -271,9 +276,12 @@ def remove_mongo_id(dat): @filters.app_template_filter() def get_video_link(data): - for link in data: - if link.get("mimeType", "").startswith("video/"): - return link.get("href") + if isinstance(data, list): + for link in data: + if link.get("mimeType", "").startswith("video/"): + return link.get("href") + elif isinstance(data, str): + return data return None