diff --git a/app/activitypub/util.py b/app/activitypub/util.py index decac310..c2e5e112 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -1203,8 +1203,9 @@ def new_instance_profile_task(instance_id: int): nodeinfo_json = nodeinfo.json() for links in nodeinfo_json['links']: if 'rel' in links and ( - links['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/2.0' or - links['rel'] == 'https://nodeinfo.diaspora.software/ns/schema/2.0'): + links['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/2.0' or # most platforms except KBIN and Lemmy v0.19.4 + links['rel'] == 'https://nodeinfo.diaspora.software/ns/schema/2.0' or # KBIN + links['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/2.1'): # Lemmy v0.19.4 (no 2.0 back-compat provided here) try: time.sleep(0.1) node = requests.get(links['href'], headers=HEADERS, timeout=5, @@ -1216,6 +1217,7 @@ def new_instance_profile_task(instance_id: int): instance.version = node_json['software']['version'] instance.nodeinfo_href = links['href'] db.session.commit() + break # most platforms (except Lemmy v0.19.4) that provide 2.1 also provide 2.0 - there's no need to check both except: return except: diff --git a/app/cli.py b/app/cli.py index eb9eb0c3..dd05bf50 100644 --- a/app/cli.py +++ b/app/cli.py @@ -184,7 +184,11 @@ def register(app): instances = Instance.query.filter(Instance.gone_forever == False, Instance.id != 1).all() HEADERS = {'User-Agent': 'PieFed/1.0', 'Accept': 'application/activity+json'} for instance in instances: - if not instance.nodeinfo_href: + nodeinfo_href = instance.nodeinfo_href + if instance.software == 'lemmy' and instance.version == '0.19.4' and instance.nodeinfo_href.endswith('nodeinfo/2.0.json'): + nodeinfo_href = None # Lemmy v0.19.4 no longer provides .well-known/nodeinfo response for 2.0, and + # 'solves' this by redirecting calls for nodeinfo/2.0.json to nodeinfo/2.1 + if not nodeinfo_href: try: nodeinfo = requests.get(f"https://{instance.domain}/.well-known/nodeinfo", headers=HEADERS, timeout=5, allow_redirects=True) @@ -194,7 +198,8 @@ def register(app): for links in nodeinfo_json['links']: if 'rel' in links and ( links['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/2.0' or - links['rel'] == 'https://nodeinfo.diaspora.software/ns/schema/2.0'): + links['rel'] == 'https://nodeinfo.diaspora.software/ns/schema/2.0' or + links['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/2.1'): instance.nodeinfo_href = links['href'] instance.failures = 0 instance.dormant = False