Showing instance actor

merge-requests/30/head
Bob Mottram 2021-08-31 17:19:55 +01:00
parent 73a5182232
commit 5238e19401
1 changed files with 86 additions and 5 deletions

View File

@ -10258,6 +10258,66 @@ class PubServer(BaseHTTPRequestHandler):
self.server.GETbusy = False self.server.GETbusy = False
return True return True
def _showInstanceActor(self, callingDomain: str, path: str,
baseDir: str, httpPrefix: str,
domain: str, domainFull: str, port: int,
onionDomain: str, i2pDomain: str,
GETstartTime, GETtimings: {},
proxyType: str, cookie: str,
debug: str,
enableSharedInbox: bool) -> bool:
"""Shows the instance actor
"""
actorJson = personLookup(domain, path, baseDir)
if not actorJson:
self._404()
return False
acceptStr = self.headers['Accept']
if onionDomain and callingDomain.endswith('.onion'):
actorDomainUrl = 'http://' + onionDomain
elif i2pDomain and callingDomain.endswith('.i2p'):
actorDomainUrl = 'http://' + i2pDomain
else:
actorDomainUrl = httpPrefix + '://' + domainFull
actorUrl = actorDomainUrl + '/users/Actor'
del actorJson['icon']
del actorJson['image']
actorJson['endpoints'] = {}
if enableSharedInbox:
actorJson['endpoints'] = {
'sharedInbox': actorDomainUrl + '/inbox'
}
actorJson['name'] = 'ACTOR'
actorJson['preferredUsername'] = 'Actor'
actorJson['id'] = actorUrl
actorJson['publicKey']['id'] = actorUrl + '#main-key'
actorJson['publicKey']['owner'] = actorUrl
actorJson['url'] = actorUrl
actorJson['inbox'] = actorUrl + '/inbox'
actorJson['followers'] = actorUrl + '/followers'
actorJson['following'] = actorUrl + '/following'
msgStr = json.dumps(actorJson, ensure_ascii=False)
if onionDomain and callingDomain.endswith('.onion'):
msgStr = msgStr.replace(httpPrefix + '://' + domainFull,
'http://' + onionDomain)
elif i2pDomain and callingDomain.endswith('.i2p'):
msgStr = msgStr.replace(httpPrefix + '://' + domainFull,
'http://' + i2pDomain)
msg = msgStr.encode('utf-8')
msglen = len(msg)
if 'application/ld+json' in acceptStr:
self._set_headers('application/ld+json', msglen,
cookie, callingDomain, False)
elif 'application/jrd+json' in acceptStr:
self._set_headers('application/jrd+json', msglen,
cookie, callingDomain, False)
else:
self._set_headers('application/activity+json', msglen,
cookie, callingDomain, False)
self._write(msg)
self.server.GETbusy = False
return True
def _showBlogPage(self, authorized: bool, def _showBlogPage(self, authorized: bool,
callingDomain: str, path: str, callingDomain: str, path: str,
baseDir: str, httpPrefix: str, baseDir: str, httpPrefix: str,
@ -11418,8 +11478,29 @@ class PubServer(BaseHTTPRequestHandler):
self._benchmarkGETtimings(GETstartTime, GETtimings, self._benchmarkGETtimings(GETstartTime, GETtimings,
'hasAccept', 'fonts') 'hasAccept', 'fonts')
# treat shared inbox paths consistently if not htmlGET and \
if self.path == '/sharedInbox' or \ self.path == '/actor' or \
self.path == '/users/actor' or \
self.path == '/Actor' or \
self.path == '/users/Actor':
self.path = '/users/inbox'
if self._showInstanceActor(callingDomain, self.path,
self.server.baseDir,
self.server.httpPrefix,
self.server.domain,
self.server.domainFull,
self.server.port,
self.server.onionDomain,
self.server.i2pDomain,
GETstartTime, GETtimings,
self.server.proxyType,
cookie, self.server.debug,
self.server.enableSharedInbox):
return
else:
self._404()
return
elif self.path == '/sharedInbox' or \
self.path == '/users/inbox' or \ self.path == '/users/inbox' or \
self.path == '/actor/inbox' or \ self.path == '/actor/inbox' or \
self.path == '/users/' + self.server.domain: self.path == '/users/' + self.server.domain: