Vestigil mastodon api

merge-requests/3/merge
Bob Mottram 2019-11-13 11:24:27 +00:00
parent 85ea49a567
commit a6ddf71cfa
1 changed files with 32 additions and 1 deletions

View File

@ -327,11 +327,38 @@ class PubServer(BaseHTTPRequestHandler):
self._write(msg)
return True
def _mastoApi(self) -> bool:
"""This is a vestigil mastodon API for the purpose
of returning an empty result to sites like
https://mastopeek.app-dist.eu
"""
if not self.path.startswith('/api/v1/'):
return False
if self.server.debug:
print('DEBUG: mastodon api '+self.path)
if self.path.startswith('/api/v1/peers'):
# This is just a dummy result.
# Showing the full list of peers would have privacy implications.
# On a large instance you are somewhat lost in the crowd, but on small
# instances a full list of peers would convey a lot of information about
# the interests of a small number of accounts
msg=json.dumps([self.server.domainFull]).encode('utf-8')
self._set_headers('application/ld+json',len(msg),None)
self._write(msg)
return True
if self.path.startswith('/api/v1/activity'):
# This is just a dummy result.
msg=json.dumps([]).encode('utf-8')
self._set_headers('application/ld+json',len(msg),None)
self._write(msg)
return True
return False
def _nodeinfo(self) -> bool:
if not self.path.startswith('/nodeinfo/2.0'):
return False
if self.server.debug:
print('DEBUG: WEBFINGER nodeinfo')
print('DEBUG: nodeinfo '+self.path)
info=metaDataNodeInfo(self.server.registration,self.server.projectVersion)
if info:
msg=json.dumps(info).encode('utf-8')
@ -1168,6 +1195,10 @@ class PubServer(BaseHTTPRequestHandler):
if self._nodeinfo():
self.server.GETbusy=False
return
# minimal mastodon api
if self._mastoApi():
self.server.GETbusy=False
return
if self.path.startswith('/login') or \
(self.path=='/' and not authorized):