Allow for attachments with no width/height

Fixes #186
This commit is contained in:
Andrew Godwin 2022-12-17 15:45:31 -07:00
parent ea99f65c26
commit 17d75c4797
1 changed files with 9 additions and 7 deletions

View File

@ -102,19 +102,13 @@ class PostAttachment(StatorModel):
### Mastodon Client API ### ### Mastodon Client API ###
def to_mastodon_json(self): def to_mastodon_json(self):
return { value = {
"id": self.pk, "id": self.pk,
"type": "image" if self.is_image() else "unknown", "type": "image" if self.is_image() else "unknown",
"url": self.full_url().absolute, "url": self.full_url().absolute,
"preview_url": self.thumbnail_url().absolute, "preview_url": self.thumbnail_url().absolute,
"remote_url": None, "remote_url": None,
"meta": { "meta": {
"original": {
"width": self.width,
"height": self.height,
"size": f"{self.width}x{self.height}",
"aspect": self.width / self.height,
},
"focus": { "focus": {
"x": self.focal_x or 0, "x": self.focal_x or 0,
"y": self.focal_y or 0, "y": self.focal_y or 0,
@ -123,3 +117,11 @@ class PostAttachment(StatorModel):
"description": self.name, "description": self.name,
"blurhash": self.blurhash, "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