Merge remote-tracking branch 'origin/main'

This commit is contained in:
rimu 2024-06-14 08:01:53 +08:00
commit baee625fce
3 changed files with 21 additions and 4 deletions

View file

@ -754,6 +754,11 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
activity_log.result = 'success'
else:
activity_log.exception_message = 'Post not found'
# Lemmy can send Announce/Update without ever sending an Announce/Create
# presumably happens with quick edits after creation (e.g. https://midwest.social/post/13348959)
# Pretend this activity was the Create, and try again.
request_json['object']['type'] = 'Create'
process_inbox_request(request_json, activitypublog_id, ip_address)
elif request_json['object']['object']['type'] == 'Note':
reply = PostReply.query.filter_by(ap_id=request_json['object']['object']['id']).first()
if reply:
@ -766,6 +771,9 @@ def process_inbox_request(request_json, activitypublog_id, ip_address):
activity_log.result = 'success'
else:
activity_log.exception_message = 'PostReply not found'
# As with Update/Page, pretend this activity was the Create, and try again.
request_json['object']['type'] = 'Create'
process_inbox_request(request_json, activitypublog_id, ip_address)
elif request_json['object']['type'] == 'Undo':
if request_json['object']['object']['type'] == 'Like' or request_json['object']['object']['type'] == 'Dislike':
activity_log.activity_type = request_json['object']['object']['type']

View file

@ -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:

View file

@ -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
@ -250,6 +255,8 @@ def register(app):
if 'admins' in instance_data:
admin_profile_ids = []
for admin in instance_data['admins']:
if admin['person']['actor_id'].startswith('http://'):
continue # suppo.fi has rogue entry in its v3/site
admin_profile_ids.append(admin['person']['actor_id'].lower())
user = find_actor_or_create(admin['person']['actor_id'])
if user and not instance.user_is_admin(user.id):