From 17d75c4797b43767a58edfefd8473826334aa416 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Sat, 17 Dec 2022 15:45:31 -0700 Subject: [PATCH] Allow for attachments with no width/height Fixes #186 --- activities/models/post_attachment.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/activities/models/post_attachment.py b/activities/models/post_attachment.py index 7fa125a..ed50771 100644 --- a/activities/models/post_attachment.py +++ b/activities/models/post_attachment.py @@ -102,19 +102,13 @@ class PostAttachment(StatorModel): ### Mastodon Client API ### def to_mastodon_json(self): - return { + value = { "id": self.pk, "type": "image" if self.is_image() else "unknown", "url": self.full_url().absolute, "preview_url": self.thumbnail_url().absolute, "remote_url": None, "meta": { - "original": { - "width": self.width, - "height": self.height, - "size": f"{self.width}x{self.height}", - "aspect": self.width / self.height, - }, "focus": { "x": self.focal_x or 0, "y": self.focal_y or 0, @@ -123,3 +117,11 @@ class PostAttachment(StatorModel): "description": self.name, "blurhash": self.blurhash, } + if self.width and self.height: + value["meta"]["original"] = { + "width": self.width, + "height": self.height, + "size": f"{self.width}x{self.height}", + "aspect": self.width / self.height, + } + return value