mirror of https://gitlab.com/bashrc2/epicyon
Check post recency before creating speaker endpoint
parent
19a9fe0970
commit
a9f5831db9
3
inbox.py
3
inbox.py
|
@ -11,6 +11,7 @@ import os
|
||||||
import datetime
|
import datetime
|
||||||
import time
|
import time
|
||||||
from linked_data_sig import verifyJsonSignature
|
from linked_data_sig import verifyJsonSignature
|
||||||
|
from utils import isRecentPost
|
||||||
from utils import getConfigParam
|
from utils import getConfigParam
|
||||||
from utils import hasUsersPath
|
from utils import hasUsersPath
|
||||||
from utils import validPostDate
|
from utils import validPostDate
|
||||||
|
@ -1404,6 +1405,7 @@ def _receiveAnnounce(recentPostsCache: {},
|
||||||
if '/statuses/' in lookupActor:
|
if '/statuses/' in lookupActor:
|
||||||
lookupActor = lookupActor.split('/statuses/')[0]
|
lookupActor = lookupActor.split('/statuses/')[0]
|
||||||
|
|
||||||
|
if isRecentPost(postJsonObject):
|
||||||
if not os.path.isfile(postFilename + '.tts'):
|
if not os.path.isfile(postFilename + '.tts'):
|
||||||
updateSpeaker(baseDir, nickname, domain,
|
updateSpeaker(baseDir, nickname, domain,
|
||||||
postJsonObject, personCache,
|
postJsonObject, personCache,
|
||||||
|
@ -2481,6 +2483,7 @@ def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int,
|
||||||
print('ERROR: unable to update ' + boxname + ' index')
|
print('ERROR: unable to update ' + boxname + ' index')
|
||||||
else:
|
else:
|
||||||
if boxname == 'inbox':
|
if boxname == 'inbox':
|
||||||
|
if isRecentPost(postJsonObject):
|
||||||
updateSpeaker(baseDir, nickname, domain,
|
updateSpeaker(baseDir, nickname, domain,
|
||||||
postJsonObject, personCache,
|
postJsonObject, personCache,
|
||||||
translate, None)
|
translate, None)
|
||||||
|
|
30
utils.py
30
utils.py
|
@ -1990,3 +1990,33 @@ def mediaFileMimeType(filename: str) -> str:
|
||||||
if not extensions.get(fileExt):
|
if not extensions.get(fileExt):
|
||||||
return 'image/png'
|
return 'image/png'
|
||||||
return extensions[fileExt]
|
return extensions[fileExt]
|
||||||
|
|
||||||
|
|
||||||
|
def isRecentPost(postJsonObject: {}, maxDays=3) -> bool:
|
||||||
|
""" Is the given post recent?
|
||||||
|
"""
|
||||||
|
if not postJsonObject.get('object'):
|
||||||
|
return False
|
||||||
|
if not isinstance(postJsonObject['object'], dict):
|
||||||
|
return False
|
||||||
|
if not postJsonObject['object'].get('published'):
|
||||||
|
return False
|
||||||
|
if not isinstance(postJsonObject['object']['published'], str):
|
||||||
|
return False
|
||||||
|
currTime = datetime.datetime.utcnow()
|
||||||
|
daysSinceEpoch = (currTime - datetime.datetime(1970, 1, 1)).days
|
||||||
|
recently = daysSinceEpoch - maxDays
|
||||||
|
|
||||||
|
publishedDateStr = postJsonObject['object']['published']
|
||||||
|
try:
|
||||||
|
publishedDate = \
|
||||||
|
datetime.datetime.strptime(publishedDateStr,
|
||||||
|
"%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
except BaseException:
|
||||||
|
return False
|
||||||
|
|
||||||
|
publishedDaysSinceEpoch = \
|
||||||
|
(publishedDate - datetime.datetime(1970, 1, 1)).days
|
||||||
|
if publishedDaysSinceEpoch < recently:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
|
@ -22,6 +22,7 @@ from posts import getPersonBox
|
||||||
from posts import isDM
|
from posts import isDM
|
||||||
from posts import downloadAnnounce
|
from posts import downloadAnnounce
|
||||||
from posts import populateRepliesJson
|
from posts import populateRepliesJson
|
||||||
|
from utils import isRecentPost
|
||||||
from utils import getConfigParam
|
from utils import getConfigParam
|
||||||
from utils import getFullDomain
|
from utils import getFullDomain
|
||||||
from utils import isEditor
|
from utils import isEditor
|
||||||
|
@ -1292,8 +1293,10 @@ def individualPostAsHtml(allowDownloads: bool,
|
||||||
return ''
|
return ''
|
||||||
postJsonObject = postJsonAnnounce
|
postJsonObject = postJsonAnnounce
|
||||||
|
|
||||||
|
if isRecentPost(postJsonObject):
|
||||||
announceFilename = \
|
announceFilename = \
|
||||||
locatePost(baseDir, nickname, domain, postJsonObject['id'])
|
locatePost(baseDir, nickname, domain,
|
||||||
|
postJsonObject['id'])
|
||||||
if announceFilename and postJsonObject.get('actor'):
|
if announceFilename and postJsonObject.get('actor'):
|
||||||
if not os.path.isfile(announceFilename + '.tts'):
|
if not os.path.isfile(announceFilename + '.tts'):
|
||||||
updateSpeaker(baseDir, nickname, domain,
|
updateSpeaker(baseDir, nickname, domain,
|
||||||
|
|
Loading…
Reference in New Issue