diff --git a/daemon.py b/daemon.py index 8cd5219e..7d9b0654 100644 --- a/daemon.py +++ b/daemon.py @@ -2949,6 +2949,9 @@ def runDaemon(projectVersion, \ if not os.path.isdir(baseDir+'/cache/actors'): print('Creating actors cache') os.mkdir(baseDir+'/cache/actors') + if not os.path.isdir(baseDir+'/cache/announce'): + print('Creating announce cache') + os.mkdir(baseDir+'/cache/announce') archiveDir=baseDir+'/archive' if not os.path.isdir(archiveDir): diff --git a/epicyon.py b/epicyon.py index b915bf7b..5e0876f2 100644 --- a/epicyon.py +++ b/epicyon.py @@ -324,6 +324,9 @@ if not os.path.isdir(baseDir+'/cache'): if not os.path.isdir(baseDir+'/cache/actors'): print('Creating actors cache') os.mkdir(baseDir+'/cache/actors') +if not os.path.isdir(baseDir+'/cache/announce'): + print('Creating announce cache') + os.mkdir(baseDir+'/cache/announce') if args.domain: domain=args.domain diff --git a/webinterface.py b/webinterface.py index 5fa1834a..cc2d4477 100644 --- a/webinterface.py +++ b/webinterface.py @@ -1023,20 +1023,31 @@ def individualPostAsHtml(baseDir: str, \ if postJsonObject.get('object'): if isinstance(postJsonObject['object'], str): # get the announced post - print('Getting Announce content for '+postJsonObject['object']) - asHeader = {'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'} - announcedJson = getJson(session,postJsonObject['object'],asHeader,None,projectVersion,httpPrefix,domain) - if announcedJson: - if not announcedJson.get('type'): - return '' - if announcedJson['type']!='Create': - return '' - actorNickname=getNicknameFromActor(postJsonObject['actor']) - actorDomain,actorPort=getDomainFromActor(postJsonObject['actor']) - titleStr+='@'+actorNickname+'@'+actorDomain+' announced:
' - postJsonObject=announcedJson + announceCacheDir=baseDir+'/cache/announce/'+nickname + if not os.path.isdir(announceCacheDir): + os.mkdir(announceCacheDir) + announceFilename=announceCacheDir+'/'+postJsonObject['object'].replace('/','#')+'.json' + if os.path.isfile(announceFilename): + print('Reading cached Announce content for '+postJsonObject['object']) + with open(announceFilename, 'r') as fp: + postJsonObject=commentjson.load(fp) else: - return '' + print('Downloading Announce content for '+postJsonObject['object']) + asHeader = {'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'} + announcedJson = getJson(session,postJsonObject['object'],asHeader,None,projectVersion,httpPrefix,domain) + if announcedJson: + if not announcedJson.get('type'): + return '' + if announcedJson['type']!='Create': + return '' + actorNickname=getNicknameFromActor(postJsonObject['actor']) + actorDomain,actorPort=getDomainFromActor(postJsonObject['actor']) + titleStr+='@'+actorNickname+'@'+actorDomain+' announced:
' + postJsonObject=announcedJson + with open(announceFilename, 'w') as fp: + commentjson.dump(postJsonObject, fp, indent=4, sort_keys=False) + else: + return '' else: return '' if not isinstance(postJsonObject['object'], dict):