From cf6a891349f01571abce03160b14be9d5e8d0354 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Fri, 30 Sep 2022 09:07:07 +0200 Subject: [PATCH] Improve/fix non-media attachment display --- app/ap_object.py | 12 ++++++++++++ app/templates/utils.html | 8 +++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/ap_object.py b/app/ap_object.py index 2889f0c..a4bbab1 100644 --- a/app/ap_object.py +++ b/app/ap_object.py @@ -1,4 +1,5 @@ import hashlib +import mimetypes from datetime import datetime from functools import cached_property from typing import Any @@ -276,6 +277,17 @@ class Attachment(BaseModel): proxied_url: str | None = None resized_url: str | None = None + @property + def mimetype(self) -> str: + mimetype = self.media_type + if not mimetype: + mimetype, _ = mimetypes.guess_type(self.url) + + if not mimetype: + return "unknown" + + return mimetype.split("/")[-1] + class RemoteObject(Object): def __init__(self, raw_object: ap.RawObject, actor: Actor): diff --git a/app/templates/utils.html b/app/templates/utils.html index ef5ed3b..2760c48 100644 --- a/app/templates/utils.html +++ b/app/templates/utils.html @@ -343,11 +343,13 @@ {% elif attachment.type == "Audio" or (attachment | has_media_type("audio")) %} {% elif attachment.type == "Link" %} - {{ attachment.url }} + {{ attachment.url | truncate(64, True) }} ({{ attachment.mimetype}}) {% else %} - {{ attachment.url }} + + {% if attachment.name %}{{ attachment.name }}{% else %}{{ attachment.url | truncate(64, True) }}{% endif %} + ({{ attachment.mimetype }}) {% endif %} - {% if object.sensitive %} + {% if object.sensitive and (attachment.type == "Image" or (attachment | has_media_type("image")) or attachment.type == "Video" or (attachment | has_media_type("video"))) %}