diff options
author | Andrew Godwin | 2022-12-17 15:45:31 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-12-17 15:45:54 -0700 |
commit | 17d75c4797b43767a58edfefd8473826334aa416 (patch) | |
tree | 9e7f8323dafcba6c743d69ec436b93e5ccafe6c5 | |
parent | ea99f65c26e476b3b10c9ae5047e0f2941e9c019 (diff) | |
download | takahe-17d75c4797b43767a58edfefd8473826334aa416.tar.gz takahe-17d75c4797b43767a58edfefd8473826334aa416.tar.bz2 takahe-17d75c4797b43767a58edfefd8473826334aa416.zip |
Allow for attachments with no width/height
Fixes #186
-rw-r--r-- | activities/models/post_attachment.py | 16 |
1 files 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 |