mirror of https://gitlab.com/bashrc2/epicyon
Remove duplicate actor search
parent
1c732f5d70
commit
73da024042
|
@ -836,7 +836,7 @@ def _desktopShowProfile(session, nickname: str, domain: str,
|
|||
isHttp = False
|
||||
if 'http://' in actor:
|
||||
isHttp = True
|
||||
actorJson = getActorJson(actor, isHttp, False, False, True)
|
||||
actorJson, asHeader = getActorJson(actor, isHttp, False, False, True)
|
||||
|
||||
_desktopShowActor(baseDir, actorJson, translate,
|
||||
systemLanguage, screenreader, espeak)
|
||||
|
@ -854,7 +854,7 @@ def _desktopShowProfileFromHandle(session, nickname: str, domain: str,
|
|||
"""Shows the profile for a handle
|
||||
Returns the actor json
|
||||
"""
|
||||
actorJson = getActorJson(handle, False, False, False, True)
|
||||
actorJson, asHeader = getActorJson(handle, False, False, False, True)
|
||||
|
||||
_desktopShowActor(baseDir, actorJson, translate,
|
||||
systemLanguage, screenreader, espeak)
|
||||
|
|
22
person.py
22
person.py
|
@ -1205,7 +1205,7 @@ def setPersonNotes(baseDir: str, nickname: str, domain: str,
|
|||
|
||||
|
||||
def getActorJson(handle: str, http: bool, gnunet: bool,
|
||||
debug: bool, quiet=False) -> {}:
|
||||
debug: bool, quiet=False) -> ({}, {}):
|
||||
"""Returns the actor json
|
||||
"""
|
||||
if debug:
|
||||
|
@ -1221,7 +1221,7 @@ def getActorJson(handle: str, http: bool, gnunet: bool,
|
|||
if not quiet or debug:
|
||||
print('getActorJson: Expected actor format: ' +
|
||||
'https://domain/@nick or https://domain/users/nick')
|
||||
return None
|
||||
return None, None
|
||||
prefixes = getProtocolPrefixes()
|
||||
for prefix in prefixes:
|
||||
handle = handle.replace(prefix, '')
|
||||
|
@ -1251,22 +1251,22 @@ def getActorJson(handle: str, http: bool, gnunet: bool,
|
|||
if '/' in domain:
|
||||
domain = domain.split('/')[0]
|
||||
if '://' + domain + '/' not in originalHandle:
|
||||
return None
|
||||
return None, None
|
||||
nickname = originalHandle.split('://' + domain + '/')[1]
|
||||
if '/' in nickname or '.' in nickname:
|
||||
return None
|
||||
return None, None
|
||||
else:
|
||||
# format: @nick@domain
|
||||
if '@' not in handle:
|
||||
if not quiet:
|
||||
print('getActorJson Syntax: --actor nickname@domain')
|
||||
return None
|
||||
return None, None
|
||||
if handle.startswith('@'):
|
||||
handle = handle[1:]
|
||||
if '@' not in handle:
|
||||
if not quiet:
|
||||
print('getActorJsonSyntax: --actor nickname@domain')
|
||||
return None
|
||||
return None, None
|
||||
nickname = handle.split('@')[0]
|
||||
domain = handle.split('@')[1]
|
||||
domain = domain.replace('\n', '').replace('\r', '')
|
||||
|
@ -1297,12 +1297,12 @@ def getActorJson(handle: str, http: bool, gnunet: bool,
|
|||
if not wfRequest:
|
||||
if not quiet:
|
||||
print('getActorJson Unable to webfinger ' + handle)
|
||||
return None
|
||||
return None, None
|
||||
if not isinstance(wfRequest, dict):
|
||||
if not quiet:
|
||||
print('getActorJson Webfinger for ' + handle +
|
||||
' did not return a dict. ' + str(wfRequest))
|
||||
return None
|
||||
return None, None
|
||||
|
||||
if not quiet:
|
||||
pprint(wfRequest)
|
||||
|
@ -1316,7 +1316,7 @@ def getActorJson(handle: str, http: bool, gnunet: bool,
|
|||
else:
|
||||
if debug:
|
||||
print('No users path in ' + handle)
|
||||
return None
|
||||
return None, None
|
||||
|
||||
profileStr = 'https://www.w3.org/ns/activitystreams'
|
||||
headersList = (
|
||||
|
@ -1353,5 +1353,5 @@ def getActorJson(handle: str, http: bool, gnunet: bool,
|
|||
if personJson:
|
||||
if not quiet:
|
||||
pprint(personJson)
|
||||
return personJson
|
||||
return None
|
||||
return personJson, asHeader
|
||||
return None, None
|
||||
|
|
4
pgp.py
4
pgp.py
|
@ -336,7 +336,7 @@ def _getPGPPublicKeyFromActor(handle: str, actorJson=None) -> str:
|
|||
public key specified
|
||||
"""
|
||||
if not actorJson:
|
||||
actorJson = getActorJson(handle, False, False, False, True)
|
||||
actorJson, asHeader = getActorJson(handle, False, False, False, True)
|
||||
if not actorJson:
|
||||
return None
|
||||
if not actorJson.get('attachment'):
|
||||
|
@ -476,7 +476,7 @@ def pgpPublicKeyUpload(baseDir: str, session,
|
|||
if debug:
|
||||
print('Getting actor for ' + handle)
|
||||
|
||||
actorJson = getActorJson(handle, False, False, debug, True)
|
||||
actorJson, asHeader = getActorJson(handle, False, False, debug, True)
|
||||
if not actorJson:
|
||||
if debug:
|
||||
print('No actor returned for ' + handle)
|
||||
|
|
|
@ -10,7 +10,6 @@ import os
|
|||
from pprint import pprint
|
||||
from utils import getOccupationName
|
||||
from utils import getLockedAccount
|
||||
from utils import hasUsersPath
|
||||
from utils import getFullDomain
|
||||
from utils import isArtist
|
||||
from utils import isDormant
|
||||
|
@ -24,10 +23,9 @@ from utils import getImageFormats
|
|||
from skills import getSkills
|
||||
from theme import getThemesList
|
||||
from person import personBoxJson
|
||||
from person import getActorJson
|
||||
from webfinger import webfingerHandle
|
||||
from session import getJson
|
||||
from posts import parseUserFeed
|
||||
from posts import getUserUrl
|
||||
from posts import getPersonBox
|
||||
from donate import getDonationUrl
|
||||
from xmpp import getXmppAddress
|
||||
|
@ -74,46 +72,20 @@ def htmlProfileAfterSearch(cssCache: {},
|
|||
accessKeys: {}) -> str:
|
||||
"""Show a profile page after a search for a fediverse address
|
||||
"""
|
||||
if hasUsersPath(profileHandle) or '/@' in profileHandle:
|
||||
searchNickname = getNicknameFromActor(profileHandle)
|
||||
searchDomain, searchPort = getDomainFromActor(profileHandle)
|
||||
else:
|
||||
if '@' not in profileHandle:
|
||||
if debug:
|
||||
print('DEBUG: no @ in ' + profileHandle)
|
||||
return None
|
||||
if profileHandle.startswith('@'):
|
||||
profileHandle = profileHandle[1:]
|
||||
if '@' not in profileHandle:
|
||||
if debug:
|
||||
print('DEBUG: no @ in ' + profileHandle)
|
||||
return None
|
||||
searchNickname = profileHandle.split('@')[0]
|
||||
searchDomain = profileHandle.split('@')[1]
|
||||
searchPort = None
|
||||
if ':' in searchDomain:
|
||||
searchPortStr = searchDomain.split(':')[1]
|
||||
if searchPortStr.isdigit():
|
||||
searchPort = int(searchPortStr)
|
||||
searchDomain = searchDomain.split(':')[0]
|
||||
if searchPort:
|
||||
if debug:
|
||||
print('DEBUG: Search for handle ' +
|
||||
str(searchNickname) + '@' + str(searchDomain) + ':' +
|
||||
str(searchPort))
|
||||
else:
|
||||
if debug:
|
||||
print('DEBUG: Search for handle ' +
|
||||
str(searchNickname) + '@' + str(searchDomain))
|
||||
if not searchNickname:
|
||||
if debug:
|
||||
print('DEBUG: No nickname found in ' + profileHandle)
|
||||
return None
|
||||
if not searchDomain:
|
||||
if debug:
|
||||
print('DEBUG: No domain found in ' + profileHandle)
|
||||
http = False
|
||||
gnunet = False
|
||||
if httpPrefix == 'http':
|
||||
http = True
|
||||
elif httpPrefix == 'gnunet':
|
||||
gnunet = True
|
||||
profileJson, asHeader = \
|
||||
getActorJson(profileHandle, http, gnunet, debug, False)
|
||||
if not profileJson:
|
||||
return None
|
||||
|
||||
personUrl = profileJson['id']
|
||||
searchDomain, searchPort = getDomainFromActor(personUrl)
|
||||
searchNickname = getNicknameFromActor(personUrl)
|
||||
searchDomainFull = getFullDomain(searchDomain, searchPort)
|
||||
|
||||
profileStr = ''
|
||||
|
@ -121,57 +93,6 @@ def htmlProfileAfterSearch(cssCache: {},
|
|||
if os.path.isfile(baseDir + '/epicyon.css'):
|
||||
cssFilename = baseDir + '/epicyon.css'
|
||||
|
||||
wf = \
|
||||
webfingerHandle(session,
|
||||
searchNickname + '@' + searchDomainFull,
|
||||
httpPrefix, cachedWebfingers,
|
||||
domain, projectVersion, debug)
|
||||
if not wf:
|
||||
if debug:
|
||||
print('DEBUG: Unable to webfinger ' +
|
||||
searchNickname + '@' + searchDomainFull)
|
||||
print('DEBUG: cachedWebfingers ' + str(cachedWebfingers))
|
||||
print('DEBUG: httpPrefix ' + httpPrefix)
|
||||
print('DEBUG: domain ' + domain)
|
||||
return None
|
||||
if not isinstance(wf, dict):
|
||||
if debug:
|
||||
print('WARN: Webfinger search for ' +
|
||||
searchNickname + '@' + searchDomainFull +
|
||||
' did not return a dict. ' +
|
||||
str(wf))
|
||||
return None
|
||||
|
||||
personUrl = None
|
||||
if wf.get('errors'):
|
||||
personUrl = httpPrefix + '://' + \
|
||||
searchDomainFull + '/users/' + searchNickname
|
||||
|
||||
profileStr = 'https://www.w3.org/ns/activitystreams'
|
||||
asHeader = {
|
||||
'Accept': 'application/activity+json; profile="' + profileStr + '"'
|
||||
}
|
||||
if not personUrl:
|
||||
personUrl = getUserUrl(wf, 0, debug)
|
||||
if not personUrl:
|
||||
# try single user instance
|
||||
asHeader = {
|
||||
'Accept': 'application/ld+json; profile="' + profileStr + '"'
|
||||
}
|
||||
personUrl = httpPrefix + '://' + searchDomainFull
|
||||
profileJson = \
|
||||
getJson(session, personUrl, asHeader, None, debug,
|
||||
projectVersion, httpPrefix, domain)
|
||||
if not profileJson:
|
||||
asHeader = {
|
||||
'Accept': 'application/ld+json; profile="' + profileStr + '"'
|
||||
}
|
||||
profileJson = \
|
||||
getJson(session, personUrl, asHeader, None, debug,
|
||||
projectVersion, httpPrefix, domain)
|
||||
if not profileJson:
|
||||
print('DEBUG: No actor returned from ' + personUrl)
|
||||
return None
|
||||
avatarUrl = ''
|
||||
if profileJson.get('icon'):
|
||||
if profileJson['icon'].get('url'):
|
||||
|
|
Loading…
Reference in New Issue