add some debugging logging

This commit is contained in:
rimu 2024-02-29 17:10:38 +13:00
parent 394f46fde3
commit 170a40738e
2 changed files with 61 additions and 49 deletions

View file

@ -902,6 +902,9 @@ def process_delete_request(request_json, activitypublog_id, ip_address):
with current_app.app_context(): with current_app.app_context():
activity_log = ActivityPubLog.query.get(activitypublog_id) activity_log = ActivityPubLog.query.get(activitypublog_id)
if 'type' in request_json and request_json['type'] == 'Delete': if 'type' in request_json and request_json['type'] == 'Delete':
if isinstance(request_json['object'], dict):
current_app.logger.error('Cannot delete, dict provided: ' + str(request_json['object']))
else:
actor_to_delete = request_json['object'].lower() actor_to_delete = request_json['object'].lower()
user = User.query.filter_by(ap_profile_id=actor_to_delete).first() user = User.query.filter_by(ap_profile_id=actor_to_delete).first()
if user: if user:

View file

@ -465,6 +465,7 @@ def refresh_community_profile_task(community_id):
def actor_json_to_model(activity_json, address, server): def actor_json_to_model(activity_json, address, server):
if activity_json['type'] == 'Person': if activity_json['type'] == 'Person':
try:
user = User(user_name=activity_json['preferredUsername'], user = User(user_name=activity_json['preferredUsername'],
title=activity_json['name'] if 'name' in activity_json else None, title=activity_json['name'] if 'name' in activity_json else None,
email=f"{address}@{server}", email=f"{address}@{server}",
@ -486,6 +487,10 @@ def actor_json_to_model(activity_json, address, server):
instance_id=find_instance_id(server) instance_id=find_instance_id(server)
# language=community_json['language'][0]['identifier'] # todo: language # language=community_json['language'][0]['identifier'] # todo: language
) )
except KeyError as e:
current_app.logger.error(f'KeyError for {address}@{server} while parsing ' + str(activity_json))
return None
if 'icon' in activity_json: if 'icon' in activity_json:
avatar = File(source_url=activity_json['icon']['url']) avatar = File(source_url=activity_json['icon']['url'])
user.avatar = avatar user.avatar = avatar
@ -1271,7 +1276,9 @@ def notify_about_post(post: Post):
def update_post_reply_from_activity(reply: PostReply, request_json: dict): def update_post_reply_from_activity(reply: PostReply, request_json: dict):
if 'source' in request_json['object'] and request_json['object']['source']['mediaType'] == 'text/markdown': if 'source' in request_json['object'] and \
isinstance(request_json['object']['source'], dict) and \
request_json['object']['source']['mediaType'] == 'text/markdown':
reply.body = request_json['object']['source']['content'] reply.body = request_json['object']['source']['content']
reply.body_html = markdown_to_html(reply.body) reply.body_html = markdown_to_html(reply.body)
elif 'content' in request_json['object']: elif 'content' in request_json['object']:
@ -1283,7 +1290,9 @@ def update_post_reply_from_activity(reply: PostReply, request_json: dict):
def update_post_from_activity(post: Post, request_json: dict): def update_post_from_activity(post: Post, request_json: dict):
post.title = request_json['object']['name'] post.title = request_json['object']['name']
if 'source' in request_json['object'] and request_json['object']['source']['mediaType'] == 'text/markdown': if 'source' in request_json['object'] and \
isinstance(request_json['object']['source'], dict) and \
request_json['object']['source']['mediaType'] == 'text/markdown':
post.body = request_json['object']['source']['content'] post.body = request_json['object']['source']['content']
post.body_html = markdown_to_html(post.body) post.body_html = markdown_to_html(post.body)
elif 'content' in request_json['object']: elif 'content' in request_json['object']: