Fix creation of covers for ActivityPub imports

`cover` comes as a JSON dict, but the code was looking for URL as
an attribute.

(This commit leaves the attribute access in place, just in case
`cover` is updated to serialize as Document proper.)
This commit is contained in:
Adeodato Simó 2023-10-16 17:32:26 -03:00
parent 6667178703
commit 3251ef0bf5
No known key found for this signature in database
GPG key ID: CDF447845F1A986F

View file

@ -482,10 +482,12 @@ class ImageField(ActivitypubFieldMixin, models.ImageField):
image_slug = value
# when it's an inline image (User avatar/icon, Book cover), it's a json
# blob, but when it's an attached image, it's just a url
if hasattr(image_slug, "url"):
url = image_slug.url
elif isinstance(image_slug, str):
if isinstance(image_slug, str):
url = image_slug
elif isinstance(image_slug, dict):
url = image_slug.get("url")
elif hasattr(image_slug, "url"): # Serialized to Image/Document object?
url = image_slug.url
else:
return None