mirror of https://gitlab.com/bashrc2/epicyon
Check if actor has changed
Can sometimes happen if Person Update has not been receivedmerge-requests/30/head
parent
04e80de244
commit
783711b46f
23
cache.py
23
cache.py
|
@ -8,13 +8,14 @@ __status__ = "Production"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
|
from session import urlExists
|
||||||
from utils import loadJson
|
from utils import loadJson
|
||||||
from utils import saveJson
|
from utils import saveJson
|
||||||
from utils import getFileCaseInsensitive
|
from utils import getFileCaseInsensitive
|
||||||
|
|
||||||
|
|
||||||
def removePersonFromCache(baseDir: str, personUrl: str,
|
def _removePersonFromCache(baseDir: str, personUrl: str,
|
||||||
personCache: {}) -> bool:
|
personCache: {}) -> bool:
|
||||||
"""Removes an actor from the cache
|
"""Removes an actor from the cache
|
||||||
"""
|
"""
|
||||||
cacheFilename = baseDir + '/cache/actors/' + \
|
cacheFilename = baseDir + '/cache/actors/' + \
|
||||||
|
@ -28,6 +29,24 @@ def removePersonFromCache(baseDir: str, personUrl: str,
|
||||||
del personCache[personUrl]
|
del personCache[personUrl]
|
||||||
|
|
||||||
|
|
||||||
|
def checkForChangedActor(session, baseDir: str,
|
||||||
|
httpPrefix: str, domainFull: str,
|
||||||
|
personUrl: str, avatarUrl: str, personCache: {},
|
||||||
|
timeoutSec: int):
|
||||||
|
"""Checks if the avatar url exists and if not then
|
||||||
|
the actor has probably changed without receiving an actor/Person Update.
|
||||||
|
So clear the actor from the cache and it will be refreshed when the next
|
||||||
|
post from them is sent
|
||||||
|
"""
|
||||||
|
if not session or not avatarUrl:
|
||||||
|
return
|
||||||
|
if domainFull in avatarUrl:
|
||||||
|
return
|
||||||
|
if urlExists(session, avatarUrl, timeoutSec, httpPrefix, domainFull):
|
||||||
|
return
|
||||||
|
_removePersonFromCache(baseDir, personUrl, personCache)
|
||||||
|
|
||||||
|
|
||||||
def storePersonInCache(baseDir: str, personUrl: str,
|
def storePersonInCache(baseDir: str, personUrl: str,
|
||||||
personJson: {}, personCache: {},
|
personJson: {}, personCache: {},
|
||||||
allowWriteToFile: bool) -> None:
|
allowWriteToFile: bool) -> None:
|
||||||
|
|
16
daemon.py
16
daemon.py
|
@ -20,7 +20,6 @@ import pyqrcode
|
||||||
# for saving images
|
# for saving images
|
||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
from siteactive import siteIsActive
|
|
||||||
from session import createSession
|
from session import createSession
|
||||||
from webfinger import webfingerMeta
|
from webfinger import webfingerMeta
|
||||||
from webfinger import webfingerNodeInfo
|
from webfinger import webfingerNodeInfo
|
||||||
|
@ -229,7 +228,7 @@ from content import extractMediaInFormPOST
|
||||||
from content import saveMediaInFormPOST
|
from content import saveMediaInFormPOST
|
||||||
from content import extractTextFieldsInPOST
|
from content import extractTextFieldsInPOST
|
||||||
from media import removeMetaData
|
from media import removeMetaData
|
||||||
from cache import removePersonFromCache
|
from cache import checkForChangedActor
|
||||||
from cache import storePersonInCache
|
from cache import storePersonInCache
|
||||||
from cache import getPersonFromCache
|
from cache import getPersonFromCache
|
||||||
from httpsig import verifyPostHeaders
|
from httpsig import verifyPostHeaders
|
||||||
|
@ -5491,14 +5490,11 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if actorJson.get('alsoKnownAs'):
|
if actorJson.get('alsoKnownAs'):
|
||||||
alsoKnownAs = actorJson['alsoKnownAs']
|
alsoKnownAs = actorJson['alsoKnownAs']
|
||||||
|
|
||||||
# check if the avatar image exists and if not then update
|
checkForChangedActor(self.server.session,
|
||||||
# the actor cache
|
self.server.baseDir, self.server.httpPrefix,
|
||||||
if optionsProfileUrl:
|
self.server.domainFull,
|
||||||
if self.server.domainFull not in optionsProfileUrl:
|
optionsActor, optionsProfileUrl,
|
||||||
if not siteIsActive(optionsProfileUrl, 3):
|
self.server.personCache, 3)
|
||||||
removePersonFromCache(self.server.baseDir,
|
|
||||||
optionsActor,
|
|
||||||
self.server.personCache)
|
|
||||||
|
|
||||||
msg = htmlPersonOptions(self.server.defaultTimeline,
|
msg = htmlPersonOptions(self.server.defaultTimeline,
|
||||||
self.server.cssCache,
|
self.server.cssCache,
|
||||||
|
|
29
session.py
29
session.py
|
@ -53,6 +53,34 @@ def createSession(proxyType: str):
|
||||||
return session
|
return session
|
||||||
|
|
||||||
|
|
||||||
|
def urlExists(session, url: str, timeoutSec=3,
|
||||||
|
httpPrefix='https', domain='testdomain') -> bool:
|
||||||
|
if not isinstance(url, str):
|
||||||
|
print('url: ' + str(url))
|
||||||
|
print('ERROR: urlExists failed, url should be a string')
|
||||||
|
return False
|
||||||
|
sessionParams = {}
|
||||||
|
sessionHeaders = {}
|
||||||
|
sessionHeaders['User-Agent'] = 'Epicyon/' + __version__
|
||||||
|
if domain:
|
||||||
|
sessionHeaders['User-Agent'] += \
|
||||||
|
'; +' + httpPrefix + '://' + domain + '/'
|
||||||
|
if not session:
|
||||||
|
print('WARN: urlExists failed, no session specified')
|
||||||
|
return True
|
||||||
|
try:
|
||||||
|
result = session.get(url, headers=sessionHeaders,
|
||||||
|
params=sessionParams,
|
||||||
|
timeout=timeoutSec)
|
||||||
|
if result:
|
||||||
|
if result.status_code == 200 or \
|
||||||
|
result.status_code == 304:
|
||||||
|
return True
|
||||||
|
except BaseException:
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def getJson(session, url: str, headers: {}, params: {},
|
def getJson(session, url: str, headers: {}, params: {},
|
||||||
version='1.2.0', httpPrefix='https',
|
version='1.2.0', httpPrefix='https',
|
||||||
domain='testdomain') -> {}:
|
domain='testdomain') -> {}:
|
||||||
|
@ -72,6 +100,7 @@ def getJson(session, url: str, headers: {}, params: {},
|
||||||
'; +' + httpPrefix + '://' + domain + '/'
|
'; +' + httpPrefix + '://' + domain + '/'
|
||||||
if not session:
|
if not session:
|
||||||
print('WARN: getJson failed, no session specified for getJson')
|
print('WARN: getJson failed, no session specified for getJson')
|
||||||
|
return None
|
||||||
try:
|
try:
|
||||||
result = session.get(url, headers=sessionHeaders, params=sessionParams)
|
result = session.get(url, headers=sessionHeaders, params=sessionParams)
|
||||||
return result.json()
|
return result.json()
|
||||||
|
|
Loading…
Reference in New Issue