Merge branch 'main' of gitlab.com:bashrc2/epicyon

merge-requests/30/head
Bob Mottram 2022-03-30 19:18:58 +01:00
commit dac061fabc
3 changed files with 39 additions and 3 deletions

View File

@ -2306,11 +2306,16 @@ def _valid_post_content(base_dir: str, nickname: str, domain: str,
if not message_json['object'].get('published'):
return False
if 'T' not in message_json['object']['published']:
published = message_json['object']['published']
if 'T' not in published:
return False
if 'Z' not in message_json['object']['published']:
if 'Z' not in published:
return False
if not valid_post_date(message_json['object']['published'], 90, debug):
if '.' in published:
# converts 2022-03-30T17:37:58.734Z into 2022-03-30T17:37:58Z
published = published.split('.')[0] + 'Z'
message_json['object']['published'] = published
if not valid_post_date(published, 90, debug):
return False
summary = None
@ -3596,6 +3601,9 @@ def _inbox_after_initial(server,
if not valid_sending_actor(session, base_dir, nickname, domain,
person_cache, post_json_object,
signing_priv_key_pem, debug, unit_test):
if debug:
print('Inbox sending actor is not valid ' +
str(post_json_object))
return False
if post_json_object.get('object'):
@ -3661,6 +3669,8 @@ def _inbox_after_initial(server,
languages_understood,
domain,
onion_domain, i2p_domain):
if debug:
print('Invalid DM ' + str(post_json_object))
return False
# get the actor being replied to
@ -3815,9 +3825,14 @@ def _inbox_after_initial(server,
debug, system_language,
domain, onion_domain, i2p_domain,
signing_priv_key_pem)
else:
if debug:
print("Inbox post is not valid " + str(post_json_object))
# if the post wasn't saved
if not os.path.isfile(destination_filename):
if debug:
print("Inbox post was not saved " + destination_filename)
return False
return True

View File

@ -268,6 +268,14 @@ def _valid_feed_date(pub_date: str, debug: bool = False) -> bool:
# convert from YY-MM-DD HH:MM:SS+00:00 to
# YY-MM-DDTHH:MM:SSZ
post_date = pub_date.replace(' ', 'T').replace('+00:00', 'Z')
if '.' in post_date:
ending = post_date.split('.')[1]
timezone_str = ''
for ending_char in ending:
if not ending_char.isdigit():
timezone_str += ending_char
if timezone_str:
post_date = post_date.split('.')[0] + timezone_str
return valid_post_date(post_date, 90, debug)
@ -325,6 +333,15 @@ def parse_feed_date(pub_date: str, unique_string_identifier: str) -> str:
if 'UT' in pub_date and 'UT' not in date_format:
continue
# remove any fraction of a second
if '.' in pub_date:
ending = pub_date.split('.')[1]
timezone_str = ''
for ending_char in ending:
if not ending_char.isdigit():
timezone_str += ending_char
if timezone_str:
pub_date = pub_date.split('.')[0] + timezone_str
try:
published_date = datetime.strptime(pub_date, date_format)
except BaseException:

View File

@ -4926,6 +4926,10 @@ def download_announce(session, base_dir: str, http_prefix: str,
base_dir, nickname, domain, post_id,
recent_posts_cache)
return None
if '.' in announced_json['published'] and \
'Z' in announced_json['published']:
announced_json['published'] = \
announced_json['published'].split('.')[0] + 'Z'
if not valid_post_date(announced_json['published'], 90, debug):
print('WARN: announced post is not recently published ' +
str(announced_json))