Less verbose

merge-requests/21/head
Bob Mottram 2021-03-14 19:53:22 +00:00
parent b207d2d674
commit 928412c34c
4 changed files with 11 additions and 9 deletions

View File

@ -1608,7 +1608,7 @@ def _estimateNumberOfEmoji(content: str) -> int:
def _validPostContent(baseDir: str, nickname: str, domain: str,
messageJson: {}, maxMentions: int, maxEmoji: int,
allowLocalNetworkAccess: bool) -> bool:
allowLocalNetworkAccess: bool, debug: bool) -> bool:
"""Is the content of a received post valid?
Check for bad html
Check for hellthreads
@ -1627,7 +1627,7 @@ def _validPostContent(baseDir: str, nickname: str, domain: str,
return False
if 'Z' not in messageJson['object']['published']:
return False
if not validPostDate(messageJson['object']['published']):
if not validPostDate(messageJson['object']['published'], 90, debug):
return False
if messageJson['object'].get('summary'):
@ -2305,7 +2305,7 @@ def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int,
nickname = handle.split('@')[0]
if _validPostContent(baseDir, nickname, domain,
postJsonObject, maxMentions, maxEmoji,
allowLocalNetworkAccess):
allowLocalNetworkAccess, debug):
if postJsonObject.get('object'):
jsonObj = postJsonObject['object']

View File

@ -144,11 +144,11 @@ def _addNewswireDictEntry(baseDir: str, domain: str,
]
def _validFeedDate(pubDate: str) -> bool:
def _validFeedDate(pubDate: str, debug=False) -> bool:
# convert from YY-MM-DD HH:MM:SS+00:00 to
# YY-MM-DDTHH:MM:SSZ
postDate = pubDate.replace(' ', 'T').replace('+00:00', 'Z')
return validPostDate(postDate, 90)
return validPostDate(postDate, 90, debug)
def parseFeedDate(pubDate: str) -> str:

View File

@ -3962,7 +3962,7 @@ def downloadAnnounce(session, baseDir: str, httpPrefix: str,
baseDir, nickname, domain, postId,
recentPostsCache)
return None
if not validPostDate(announcedJson['published']):
if not validPostDate(announcedJson['published'], 90, debug):
_rejectAnnounce(announceFilename,
baseDir, nickname, domain, postId,
recentPostsCache)

View File

@ -100,7 +100,7 @@ def hasUsersPath(pathStr: str) -> bool:
return False
def validPostDate(published: str, maxAgeDays=90) -> bool:
def validPostDate(published: str, maxAgeDays=90, debug=False) -> bool:
"""Returns true if the published date is recent and is not in the future
"""
baselineTime = datetime.datetime(1970, 1, 1)
@ -118,11 +118,13 @@ def validPostDate(published: str, maxAgeDays=90) -> bool:
postDaysSinceEpoch = daysDiff.days
if postDaysSinceEpoch > nowDaysSinceEpoch:
print("Inbox post has a published date in the future!")
if debug:
print("Inbox post has a published date in the future!")
return False
if nowDaysSinceEpoch - postDaysSinceEpoch >= maxAgeDays:
print("Inbox post is not recent enough")
if debug:
print("Inbox post is not recent enough")
return False
return True