From 4a975dcbfa98e2468ff4bc5c64bff7c1b5a1f52c Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Wed, 20 Jul 2022 20:59:29 +0200 Subject: [PATCH] Add support for displaying Page object --- app/ap_object.py | 20 +++++++++++++++++--- app/main.py | 5 ++--- app/templates.py | 4 +++- app/templates/utils.html | 5 +++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app/ap_object.py b/app/ap_object.py index 2b986f0..bbcefc4 100644 --- a/app/ap_object.py +++ b/app/ap_object.py @@ -76,6 +76,20 @@ class Object: def attachments(self) -> list["Attachment"]: attachments = [] for obj in ap.as_list(self.ap_object.get("attachment", [])): + if obj.get("type") == "Link": + attachments.append( + Attachment.parse_obj( + { + "proxiedUrl": None, + "resizedUrl": None, + "mediaType": None, + "type": "Link", + "url": obj["href"], + } + ) + ) + continue + proxied_url = proxied_media_url(obj["url"]) attachments.append( Attachment.parse_obj( @@ -189,12 +203,12 @@ class BaseModel(pydantic.BaseModel): class Attachment(BaseModel): type: str - media_type: str + media_type: str | None name: str | None url: str - # Extra fields for the templates - proxied_url: str + # Extra fields for the templates (and only for media) + proxied_url: str | None = None resized_url: str | None = None diff --git a/app/main.py b/app/main.py index 082b15c..aa4ac97 100644 --- a/app/main.py +++ b/app/main.py @@ -78,7 +78,6 @@ _RESIZED_CACHE: MutableMapping[tuple[str, int], tuple[bytes, str, Any]] = LFUCac # Next: # - UI support for updating posts # - Support for processing update -# - Page support # - Article support # - Fix tests # - Fix SQL tx in the codebase @@ -1087,8 +1086,8 @@ async def _gen_rss_feed( if outbox_object.attachments: for attachment in outbox_object.attachments: - if attachment.type == "Image" or attachment.media_type.startswith( - "image" + if attachment.type == "Image" or ( + attachment.media_type and attachment.media_type.startswith("image") ): content += f'' # TODO(ts): other attachment types diff --git a/app/templates.py b/app/templates.py index f09f31d..b48dfdc 100644 --- a/app/templates.py +++ b/app/templates.py @@ -315,7 +315,9 @@ def _timeago(original_dt: datetime) -> str: def _has_media_type(attachment: Attachment, media_type_prefix: str) -> bool: - return attachment.media_type.startswith(media_type_prefix) + if attachment.media_type: + return attachment.media_type.startswith(media_type_prefix) + return False def _format_date(dt: datetime) -> str: diff --git a/app/templates/utils.html b/app/templates/utils.html index 100eb36..1a282aa 100644 --- a/app/templates/utils.html +++ b/app/templates/utils.html @@ -254,6 +254,8 @@ {% elif attachment.type == "Audio" or (attachment | has_media_type("audio")) %} + {% elif attachment.type == "Link" %} + {{ attachment.url }} {% else %} {{ attachment.url }} {% endif %} @@ -262,7 +264,7 @@ {% endmacro %} {% macro display_object(object, likes=[], shares=[], webmentions=[], expanded=False, actors_metadata={}) %} -{% if object.ap_type in ["Note", "Article", "Video"] %} +{% if object.ap_type in ["Note", "Article", "Video", "Page"] %}
{{ display_actor(object.actor, actors_metadata, embedded=True) }} @@ -272,7 +274,6 @@ {% endif %} - {% if object.summary %}

{{ object.summary | clean_html(object) | safe }}

{% endif %}