mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-11-15 03:04:28 +00:00
Cache video
This commit is contained in:
parent
9768e673d7
commit
35f9275456
3 changed files with 29 additions and 7 deletions
|
@ -230,6 +230,17 @@ def task_cache_attachments() -> _Response:
|
||||||
|
|
||||||
obj = activity.get_object()
|
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
|
# Iter the attachments
|
||||||
for attachment in obj._data.get("attachment", []):
|
for attachment in obj._data.get("attachment", []):
|
||||||
try:
|
try:
|
||||||
|
@ -284,9 +295,12 @@ def task_cache_actor() -> _Response:
|
||||||
# )
|
# )
|
||||||
|
|
||||||
app.logger.info(f"actor cached for {iri}")
|
app.logger.info(f"actor cached for {iri}")
|
||||||
if activity.has_type(
|
if not activity.has_type([ap.ActivityType.CREATE, ap.ActivityType.ANNOUNCE]):
|
||||||
[ap.ActivityType.CREATE, ap.ActivityType.ANNOUNCE]
|
return ""
|
||||||
) and activity.get_object()._data.get("attachment", []):
|
|
||||||
|
if activity.get_object()._data.get(
|
||||||
|
"attachment", []
|
||||||
|
) or activity.get_object().has_type(ap.ActivityType.VIDEO):
|
||||||
Tasks.cache_attachments(iri)
|
Tasks.cache_attachments(iri)
|
||||||
|
|
||||||
except (ActivityGoneError, ActivityNotFoundError):
|
except (ActivityGoneError, ActivityNotFoundError):
|
||||||
|
|
|
@ -67,7 +67,7 @@
|
||||||
{% if obj.summary %}<p class="p-summary">{{ obj.summary | clean | safe }}</p>{% endif %}
|
{% if obj.summary %}<p class="p-summary">{{ obj.summary | clean | safe }}</p>{% endif %}
|
||||||
{% if obj | has_type('Video') %}
|
{% if obj | has_type('Video') %}
|
||||||
<div class="note-video">
|
<div class="note-video">
|
||||||
<video controls preload="metadata" src="{{ obj.url | get_video_link }}" width="480">
|
<video controls preload="metadata" src="{{ obj.url | get_video_url }}" width="480">
|
||||||
</video>
|
</video>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -249,6 +249,11 @@ def get_attachment_url(url, size):
|
||||||
return _get_file_url(url, size, Kind.ATTACHMENT)
|
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()
|
@filters.app_template_filter()
|
||||||
def get_og_image_url(url, size=100):
|
def get_og_image_url(url, size=100):
|
||||||
try:
|
try:
|
||||||
|
@ -271,9 +276,12 @@ def remove_mongo_id(dat):
|
||||||
|
|
||||||
@filters.app_template_filter()
|
@filters.app_template_filter()
|
||||||
def get_video_link(data):
|
def get_video_link(data):
|
||||||
|
if isinstance(data, list):
|
||||||
for link in data:
|
for link in data:
|
||||||
if link.get("mimeType", "").startswith("video/"):
|
if link.get("mimeType", "").startswith("video/"):
|
||||||
return link.get("href")
|
return link.get("href")
|
||||||
|
elif isinstance(data, str):
|
||||||
|
return data
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue