summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Manfre2022-12-17 17:42:29 -0500
committerGitHub2022-12-17 15:42:29 -0700
commitea99f65c26e476b3b10c9ae5047e0f2941e9c019 (patch)
tree2f2938070692ac6530c11ef585b76da8c3c417ff
parent24b5d08f9b7e987a578143aea98ccaa69ba80ce5 (diff)
downloadtakahe-ea99f65c26e476b3b10c9ae5047e0f2941e9c019.tar.gz
takahe-ea99f65c26e476b3b10c9ae5047e0f2941e9c019.tar.bz2
takahe-ea99f65c26e476b3b10c9ae5047e0f2941e9c019.zip
Icon and image for Identity could be a list
-rw-r--r--core/ld.py14
-rw-r--r--users/models/identity.py12
2 files changed, 23 insertions, 3 deletions
diff --git a/core/ld.py b/core/ld.py
index 24088ec..946e030 100644
--- a/core/ld.py
+++ b/core/ld.py
@@ -456,6 +456,20 @@ def parse_ld_date(value: str | None) -> datetime.datetime | None:
)
+def get_first_image_url(data) -> str | None:
+ """
+ 'icon' and 'image' fields might be a dict or a list. Return the first
+ 'url' for something that looks to be for an image.
+ """
+ if isinstance(data, list):
+ for itm in data:
+ if isinstance(itm, dict) and "url" in itm:
+ return itm["url"]
+ elif isinstance(data, dict):
+ return data.get("url")
+ return None
+
+
def media_type_from_filename(filename):
_, extension = os.path.splitext(filename)
if extension == ".png":
diff --git a/users/models/identity.py b/users/models/identity.py
index afec0e7..cf5b711 100644
--- a/users/models/identity.py
+++ b/users/models/identity.py
@@ -14,7 +14,13 @@ from django.utils.functional import lazy
from core.exceptions import ActorMismatchError
from core.files import get_remote_file
from core.html import sanitize_post, strip_html
-from core.ld import canonicalise, format_ld_date, get_list, media_type_from_filename
+from core.ld import (
+ canonicalise,
+ format_ld_date,
+ get_first_image_url,
+ get_list,
+ media_type_from_filename,
+)
from core.models import Config
from core.signatures import HttpSignature, RsaKeys
from core.uploads import upload_namer
@@ -487,8 +493,8 @@ class Identity(StatorModel):
self.manually_approves_followers = document.get("manuallyApprovesFollowers")
self.public_key = document.get("publicKey", {}).get("publicKeyPem")
self.public_key_id = document.get("publicKey", {}).get("id")
- self.icon_uri = document.get("icon", {}).get("url")
- self.image_uri = document.get("image", {}).get("url")
+ self.icon_uri = get_first_image_url(document.get("icon", None))
+ self.image_uri = get_first_image_url(document.get("image", None))
self.discoverable = document.get("toot:discoverable", True)
# Profile links/metadata
self.metadata = []