Handle post without object

main
bashrc 2026-02-20 10:43:00 +00:00
parent 4fdd8020ff
commit fee4e3eb26
1 changed files with 20 additions and 14 deletions

View File

@ -12,6 +12,7 @@ from utils import acct_dir
from utils import resembles_url from utils import resembles_url
from utils import remove_html from utils import remove_html
from utils import text_in_file from utils import text_in_file
from utils import has_object_dict
def get_quote_toot_url(post_json_object: str) -> str: def get_quote_toot_url(post_json_object: str) -> str:
@ -23,16 +24,21 @@ def get_quote_toot_url(post_json_object: str) -> str:
'quoteUri', 'quoteUrl', 'quoteReply', 'toot:quoteReply', 'quoteUri', 'quoteUrl', 'quoteReply', 'toot:quoteReply',
'_misskey_quote', 'quote' '_misskey_quote', 'quote'
) )
post_obj = post_json_object
if has_object_dict(post_json_object):
post_obj = post_json_object['object']
for fieldname in object_quote_url_fields: for fieldname in object_quote_url_fields:
if not post_json_object['object'].get(fieldname): if not post_obj.get(fieldname):
continue continue
quote_url = post_json_object['object'][fieldname] quote_url = post_obj[fieldname]
if isinstance(quote_url, str): if isinstance(quote_url, str):
if resembles_url(quote_url): if resembles_url(quote_url):
return remove_html(quote_url) return remove_html(quote_url)
# as defined by FEP-dd4b # as defined by FEP-dd4b
# https://codeberg.org/fediverse/fep/src/branch/main/fep/dd4b/fep-dd4b.md # https://codeberg.org/fediverse/fep/src/branch/main/fep/dd4b/fep-dd4b.md
if has_object_dict(post_json_object):
if ((post_json_object.get('content') or if ((post_json_object.get('content') or
post_json_object.get('contentMap')) and post_json_object.get('contentMap')) and
(not post_json_object['object'].get('content') and (not post_json_object['object'].get('content') and
@ -44,13 +50,13 @@ def get_quote_toot_url(post_json_object: str) -> str:
return remove_html(quote_url) return remove_html(quote_url)
# Other ActivityPub implementation - adding a Link tag # Other ActivityPub implementation - adding a Link tag
if not post_json_object['object'].get('tag'): if post_obj.get('tag'):
return '' return ''
if not isinstance(post_json_object['object']['tag'], list): if not isinstance(post_obj['tag'], list):
return '' return ''
for item in post_json_object['object']['tag']: for item in post_obj['tag']:
if not isinstance(item, dict): if not isinstance(item, dict):
continue continue
if item.get('rel'): if item.get('rel'):