Tidy pwa manifest

merge-requests/8/head
Bob Mottram 2020-08-31 15:31:00 +01:00
parent 47d68b3c4e
commit 7043f79355
1 changed files with 97 additions and 91 deletions

170
daemon.py
View File

@ -3435,86 +3435,10 @@ class PubServer(BaseHTTPRequestHandler):
self._redirect_headers(actorStr, cookie, callingDomain)
self.server.POSTbusy = False
def do_GET(self):
callingDomain = self.server.domainFull
if self.headers.get('Host'):
callingDomain = self.headers['Host']
if self.server.onionDomain:
if callingDomain != self.server.domain and \
callingDomain != self.server.domainFull and \
callingDomain != self.server.onionDomain:
print('GET domain blocked: ' + callingDomain)
self._400()
return
else:
if callingDomain != self.server.domain and \
callingDomain != self.server.domainFull:
print('GET domain blocked: ' + callingDomain)
self._400()
return
GETstartTime = time.time()
GETtimings = {}
self._benchmarkGETtimings(GETstartTime, GETtimings, None, 'start')
# Since fediverse crawlers are quite active,
# make returning info to them high priority
# get nodeinfo endpoint
if self._nodeinfo(callingDomain):
return
self._benchmarkGETtimings(GETstartTime, GETtimings,
'start', '_nodeinfo(callingDomain)')
# minimal mastodon api
if self._mastoApi(callingDomain):
return
self._benchmarkGETtimings(GETstartTime, GETtimings,
'_nodeinfo(callingDomain)',
'_mastoApi(callingDomain)')
if self.path == '/logout':
msg = \
htmlLogin(self.server.translate,
self.server.baseDir, False).encode('utf-8')
self._logout_headers('text/html', len(msg), callingDomain)
self._write(msg)
self._benchmarkGETtimings(GETstartTime, GETtimings,
'_nodeinfo(callingDomain)',
'logout')
return
self._benchmarkGETtimings(GETstartTime, GETtimings,
'_nodeinfo(callingDomain)',
'show logout')
# replace https://domain/@nick with https://domain/users/nick
if self.path.startswith('/@'):
self.path = self.path.replace('/@', '/users/')
# redirect music to #nowplaying list
if self.path == '/music' or self.path == '/nowplaying':
self.path = '/tags/nowplaying'
if self.server.debug:
print('DEBUG: GET from ' + self.server.baseDir +
' path: ' + self.path + ' busy: ' +
str(self.server.GETbusy))
if self.server.debug:
print(str(self.headers))
cookie = None
if self.headers.get('Cookie'):
cookie = self.headers['Cookie']
self._benchmarkGETtimings(GETstartTime, GETtimings,
'show logout', 'get cookie')
# manifest for progressive web apps
if '/manifest.json' in self.path:
def _progressiveWebAppManifest(self, callingDomain: str,
GETstartTime, GETtimings: {}):
"""gets the PWA manifest
"""
app1 = "https://f-droid.org/en/packages/eu.siacs.conversations"
app2 = "https://staging.f-droid.org/en/packages/im.vector.app"
manifest = {
@ -3598,14 +3522,96 @@ class PubServer(BaseHTTPRequestHandler):
}
msg = json.dumps(manifest,
ensure_ascii=False).encode('utf-8')
self._set_headers('application/json',
len(msg),
self._set_headers('application/json', len(msg),
None, callingDomain)
self._write(msg)
if self.server.debug:
print('Sent manifest: ' + callingDomain)
self._benchmarkGETtimings(GETstartTime, GETtimings,
'show logout', 'send manifest')
def do_GET(self):
callingDomain = self.server.domainFull
if self.headers.get('Host'):
callingDomain = self.headers['Host']
if self.server.onionDomain:
if callingDomain != self.server.domain and \
callingDomain != self.server.domainFull and \
callingDomain != self.server.onionDomain:
print('GET domain blocked: ' + callingDomain)
self._400()
return
else:
if callingDomain != self.server.domain and \
callingDomain != self.server.domainFull:
print('GET domain blocked: ' + callingDomain)
self._400()
return
GETstartTime = time.time()
GETtimings = {}
self._benchmarkGETtimings(GETstartTime, GETtimings, None, 'start')
# Since fediverse crawlers are quite active,
# make returning info to them high priority
# get nodeinfo endpoint
if self._nodeinfo(callingDomain):
return
self._benchmarkGETtimings(GETstartTime, GETtimings,
'start', '_nodeinfo(callingDomain)')
# minimal mastodon api
if self._mastoApi(callingDomain):
return
self._benchmarkGETtimings(GETstartTime, GETtimings,
'_nodeinfo(callingDomain)',
'_mastoApi(callingDomain)')
if self.path == '/logout':
msg = \
htmlLogin(self.server.translate,
self.server.baseDir, False).encode('utf-8')
self._logout_headers('text/html', len(msg), callingDomain)
self._write(msg)
self._benchmarkGETtimings(GETstartTime, GETtimings,
'_nodeinfo(callingDomain)',
'logout')
return
self._benchmarkGETtimings(GETstartTime, GETtimings,
'_nodeinfo(callingDomain)',
'show logout')
# replace https://domain/@nick with https://domain/users/nick
if self.path.startswith('/@'):
self.path = self.path.replace('/@', '/users/')
# redirect music to #nowplaying list
if self.path == '/music' or self.path == '/nowplaying':
self.path = '/tags/nowplaying'
if self.server.debug:
print('DEBUG: GET from ' + self.server.baseDir +
' path: ' + self.path + ' busy: ' +
str(self.server.GETbusy))
if self.server.debug:
print(str(self.headers))
cookie = None
if self.headers.get('Cookie'):
cookie = self.headers['Cookie']
self._benchmarkGETtimings(GETstartTime, GETtimings,
'show logout', 'get cookie')
# manifest for progressive web apps
if '/manifest.json' in self.path:
self._progressiveWebAppManifest(callingDomain,
GETstartTime, GETtimings)
return
# favicon image