Icon and image for Identity could be a list
This commit is contained in:
parent
24b5d08f9b
commit
ea99f65c26
14
core/ld.py
14
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):
|
def media_type_from_filename(filename):
|
||||||
_, extension = os.path.splitext(filename)
|
_, extension = os.path.splitext(filename)
|
||||||
if extension == ".png":
|
if extension == ".png":
|
||||||
|
@ -14,7 +14,13 @@ from django.utils.functional import lazy
|
|||||||
from core.exceptions import ActorMismatchError
|
from core.exceptions import ActorMismatchError
|
||||||
from core.files import get_remote_file
|
from core.files import get_remote_file
|
||||||
from core.html import sanitize_post, strip_html
|
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.models import Config
|
||||||
from core.signatures import HttpSignature, RsaKeys
|
from core.signatures import HttpSignature, RsaKeys
|
||||||
from core.uploads import upload_namer
|
from core.uploads import upload_namer
|
||||||
@ -487,8 +493,8 @@ class Identity(StatorModel):
|
|||||||
self.manually_approves_followers = document.get("manuallyApprovesFollowers")
|
self.manually_approves_followers = document.get("manuallyApprovesFollowers")
|
||||||
self.public_key = document.get("publicKey", {}).get("publicKeyPem")
|
self.public_key = document.get("publicKey", {}).get("publicKeyPem")
|
||||||
self.public_key_id = document.get("publicKey", {}).get("id")
|
self.public_key_id = document.get("publicKey", {}).get("id")
|
||||||
self.icon_uri = document.get("icon", {}).get("url")
|
self.icon_uri = get_first_image_url(document.get("icon", None))
|
||||||
self.image_uri = document.get("image", {}).get("url")
|
self.image_uri = get_first_image_url(document.get("image", None))
|
||||||
self.discoverable = document.get("toot:discoverable", True)
|
self.discoverable = document.get("toot:discoverable", True)
|
||||||
# Profile links/metadata
|
# Profile links/metadata
|
||||||
self.metadata = []
|
self.metadata = []
|
||||||
|
Reference in New Issue
Block a user