Add support for displaying Page object

This commit is contained in:
Thomas Sileo 2022-07-20 20:59:29 +02:00
parent 7ba2408c8d
commit 4a975dcbfa
4 changed files with 25 additions and 9 deletions

View File

@ -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

View File

@ -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'<img src="{attachment.url}">'
# TODO(ts): other attachment types

View File

@ -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:

View File

@ -254,6 +254,8 @@
<video controls preload="metadata" src="{{ attachment.url | media_proxy_url }}"{% if attachment.name %} title="{{ attachment.name }}"{% endif %} class="attachment"></video>
{% elif attachment.type == "Audio" or (attachment | has_media_type("audio")) %}
<audio controls preload="metadata" src="{{ attachment.url | media_proxy_url }}"{% if attachment.name%} title="{{ attachment.name }}"{% endif %} style="width:480px;" class="attachment"></audio>
{% elif attachment.type == "Link" %}
<a href="{{ attachment.url }}" class="attachment" style="display:inline-block;margin-bottom: 15px;">{{ attachment.url }}</a>
{% else %}
<a href="{{ attachment.url | media_proxy_url }}"{% if attachment.name %} title="{{ attachment.name }}"{% endif %} class="attachment">{{ attachment.url }}</a>
{% 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"] %}
<div class="ap-object {% if expanded %}ap-object-expanded {% endif %}h-entry" id="{{ object.permalink_id }}">
{{ display_actor(object.actor, actors_metadata, embedded=True) }}
@ -272,7 +274,6 @@
</a>
{% endif %}
{% if object.summary %}
<p class="p-summary">{{ object.summary | clean_html(object) | safe }}</p>
{% endif %}