Remove duplicate actor search

merge-requests/30/head
Bob Mottram 2021-06-03 20:46:35 +01:00
parent 1c732f5d70
commit 73da024042
4 changed files with 28 additions and 107 deletions

View File

@ -836,7 +836,7 @@ def _desktopShowProfile(session, nickname: str, domain: str,
isHttp = False isHttp = False
if 'http://' in actor: if 'http://' in actor:
isHttp = True isHttp = True
actorJson = getActorJson(actor, isHttp, False, False, True) actorJson, asHeader = getActorJson(actor, isHttp, False, False, True)
_desktopShowActor(baseDir, actorJson, translate, _desktopShowActor(baseDir, actorJson, translate,
systemLanguage, screenreader, espeak) systemLanguage, screenreader, espeak)
@ -854,7 +854,7 @@ def _desktopShowProfileFromHandle(session, nickname: str, domain: str,
"""Shows the profile for a handle """Shows the profile for a handle
Returns the actor json Returns the actor json
""" """
actorJson = getActorJson(handle, False, False, False, True) actorJson, asHeader = getActorJson(handle, False, False, False, True)
_desktopShowActor(baseDir, actorJson, translate, _desktopShowActor(baseDir, actorJson, translate,
systemLanguage, screenreader, espeak) systemLanguage, screenreader, espeak)

View File

@ -1205,7 +1205,7 @@ def setPersonNotes(baseDir: str, nickname: str, domain: str,
def getActorJson(handle: str, http: bool, gnunet: bool, def getActorJson(handle: str, http: bool, gnunet: bool,
debug: bool, quiet=False) -> {}: debug: bool, quiet=False) -> ({}, {}):
"""Returns the actor json """Returns the actor json
""" """
if debug: if debug:
@ -1221,7 +1221,7 @@ def getActorJson(handle: str, http: bool, gnunet: bool,
if not quiet or debug: if not quiet or debug:
print('getActorJson: Expected actor format: ' + print('getActorJson: Expected actor format: ' +
'https://domain/@nick or https://domain/users/nick') 'https://domain/@nick or https://domain/users/nick')
return None return None, None
prefixes = getProtocolPrefixes() prefixes = getProtocolPrefixes()
for prefix in prefixes: for prefix in prefixes:
handle = handle.replace(prefix, '') handle = handle.replace(prefix, '')
@ -1251,22 +1251,22 @@ def getActorJson(handle: str, http: bool, gnunet: bool,
if '/' in domain: if '/' in domain:
domain = domain.split('/')[0] domain = domain.split('/')[0]
if '://' + domain + '/' not in originalHandle: if '://' + domain + '/' not in originalHandle:
return None return None, None
nickname = originalHandle.split('://' + domain + '/')[1] nickname = originalHandle.split('://' + domain + '/')[1]
if '/' in nickname or '.' in nickname: if '/' in nickname or '.' in nickname:
return None return None, None
else: else:
# format: @nick@domain # format: @nick@domain
if '@' not in handle: if '@' not in handle:
if not quiet: if not quiet:
print('getActorJson Syntax: --actor nickname@domain') print('getActorJson Syntax: --actor nickname@domain')
return None return None, None
if handle.startswith('@'): if handle.startswith('@'):
handle = handle[1:] handle = handle[1:]
if '@' not in handle: if '@' not in handle:
if not quiet: if not quiet:
print('getActorJsonSyntax: --actor nickname@domain') print('getActorJsonSyntax: --actor nickname@domain')
return None return None, None
nickname = handle.split('@')[0] nickname = handle.split('@')[0]
domain = handle.split('@')[1] domain = handle.split('@')[1]
domain = domain.replace('\n', '').replace('\r', '') domain = domain.replace('\n', '').replace('\r', '')
@ -1297,12 +1297,12 @@ def getActorJson(handle: str, http: bool, gnunet: bool,
if not wfRequest: if not wfRequest:
if not quiet: if not quiet:
print('getActorJson Unable to webfinger ' + handle) print('getActorJson Unable to webfinger ' + handle)
return None return None, None
if not isinstance(wfRequest, dict): if not isinstance(wfRequest, dict):
if not quiet: if not quiet:
print('getActorJson Webfinger for ' + handle + print('getActorJson Webfinger for ' + handle +
' did not return a dict. ' + str(wfRequest)) ' did not return a dict. ' + str(wfRequest))
return None return None, None
if not quiet: if not quiet:
pprint(wfRequest) pprint(wfRequest)
@ -1316,7 +1316,7 @@ def getActorJson(handle: str, http: bool, gnunet: bool,
else: else:
if debug: if debug:
print('No users path in ' + handle) print('No users path in ' + handle)
return None return None, None
profileStr = 'https://www.w3.org/ns/activitystreams' profileStr = 'https://www.w3.org/ns/activitystreams'
headersList = ( headersList = (
@ -1353,5 +1353,5 @@ def getActorJson(handle: str, http: bool, gnunet: bool,
if personJson: if personJson:
if not quiet: if not quiet:
pprint(personJson) pprint(personJson)
return personJson return personJson, asHeader
return None return None, None

4
pgp.py
View File

@ -336,7 +336,7 @@ def _getPGPPublicKeyFromActor(handle: str, actorJson=None) -> str:
public key specified public key specified
""" """
if not actorJson: if not actorJson:
actorJson = getActorJson(handle, False, False, False, True) actorJson, asHeader = getActorJson(handle, False, False, False, True)
if not actorJson: if not actorJson:
return None return None
if not actorJson.get('attachment'): if not actorJson.get('attachment'):
@ -476,7 +476,7 @@ def pgpPublicKeyUpload(baseDir: str, session,
if debug: if debug:
print('Getting actor for ' + handle) print('Getting actor for ' + handle)
actorJson = getActorJson(handle, False, False, debug, True) actorJson, asHeader = getActorJson(handle, False, False, debug, True)
if not actorJson: if not actorJson:
if debug: if debug:
print('No actor returned for ' + handle) print('No actor returned for ' + handle)

View File

@ -10,7 +10,6 @@ import os
from pprint import pprint from pprint import pprint
from utils import getOccupationName from utils import getOccupationName
from utils import getLockedAccount from utils import getLockedAccount
from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
from utils import isArtist from utils import isArtist
from utils import isDormant from utils import isDormant
@ -24,10 +23,9 @@ from utils import getImageFormats
from skills import getSkills from skills import getSkills
from theme import getThemesList from theme import getThemesList
from person import personBoxJson from person import personBoxJson
from person import getActorJson
from webfinger import webfingerHandle from webfinger import webfingerHandle
from session import getJson
from posts import parseUserFeed from posts import parseUserFeed
from posts import getUserUrl
from posts import getPersonBox from posts import getPersonBox
from donate import getDonationUrl from donate import getDonationUrl
from xmpp import getXmppAddress from xmpp import getXmppAddress
@ -74,46 +72,20 @@ def htmlProfileAfterSearch(cssCache: {},
accessKeys: {}) -> str: accessKeys: {}) -> str:
"""Show a profile page after a search for a fediverse address """Show a profile page after a search for a fediverse address
""" """
if hasUsersPath(profileHandle) or '/@' in profileHandle: http = False
searchNickname = getNicknameFromActor(profileHandle) gnunet = False
searchDomain, searchPort = getDomainFromActor(profileHandle) if httpPrefix == 'http':
else: http = True
if '@' not in profileHandle: elif httpPrefix == 'gnunet':
if debug: gnunet = True
print('DEBUG: no @ in ' + profileHandle) profileJson, asHeader = \
return None getActorJson(profileHandle, http, gnunet, debug, False)
if profileHandle.startswith('@'): if not profileJson:
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)
return None return None
personUrl = profileJson['id']
searchDomain, searchPort = getDomainFromActor(personUrl)
searchNickname = getNicknameFromActor(personUrl)
searchDomainFull = getFullDomain(searchDomain, searchPort) searchDomainFull = getFullDomain(searchDomain, searchPort)
profileStr = '' profileStr = ''
@ -121,57 +93,6 @@ def htmlProfileAfterSearch(cssCache: {},
if os.path.isfile(baseDir + '/epicyon.css'): if os.path.isfile(baseDir + '/epicyon.css'):
cssFilename = 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 = '' avatarUrl = ''
if profileJson.get('icon'): if profileJson.get('icon'):
if profileJson['icon'].get('url'): if profileJson['icon'].get('url'):