Support different background formats

main
Bob Mottram 2020-07-25 18:07:22 +01:00
parent 69749a958c
commit a428372e8e
2 changed files with 59 additions and 58 deletions

114
daemon.py
View File

@ -1840,35 +1840,36 @@ class PubServer(BaseHTTPRequestHandler):
self._benchmarkGETtimings(GETstartTime, GETtimings, 16)
# login screen background image
if self.path == '/login-background.png':
mediaFilename = \
self.server.baseDir + '/accounts/login-background.png'
if os.path.isfile(mediaFilename):
if self._etag_exists(mediaFilename):
# The file has not changed
self._304()
return
for ext in ('png', 'jpg', 'gif'):
# login screen background image
if self.path == '/login-background.' + ext:
mediaFilename = \
self.server.baseDir + '/accounts/login-background.' + ext
if os.path.isfile(mediaFilename):
if self._etag_exists(mediaFilename):
# The file has not changed
self._304()
return
tries = 0
mediaBinary = None
while tries < 5:
try:
with open(mediaFilename, 'rb') as avFile:
mediaBinary = avFile.read()
break
except Exception as e:
print(e)
time.sleep(1)
tries += 1
if mediaBinary:
self._set_headers_etag(mediaFilename, 'image/png',
mediaBinary, cookie,
callingDomain)
self._write(mediaBinary)
return
self._404()
return
tries = 0
mediaBinary = None
while tries < 5:
try:
with open(mediaFilename, 'rb') as avFile:
mediaBinary = avFile.read()
break
except Exception as e:
print(e)
time.sleep(1)
tries += 1
if mediaBinary:
self._set_headers_etag(mediaFilename, 'image/' + ext,
mediaBinary, cookie,
callingDomain)
self._write(mediaBinary)
return
self._404()
return
# QR code for account handle
if '/users/' in self.path and \
@ -1941,35 +1942,36 @@ class PubServer(BaseHTTPRequestHandler):
self._benchmarkGETtimings(GETstartTime, GETtimings, 17)
# follow screen background image
if self.path == '/follow-background.png':
mediaFilename = \
self.server.baseDir + '/accounts/follow-background.png'
if os.path.isfile(mediaFilename):
if self._etag_exists(mediaFilename):
# The file has not changed
self._304()
return
for ext in ('png', 'jpg', 'gif'):
# follow screen background image
if self.path == '/follow-background.' + ext:
mediaFilename = \
self.server.baseDir + '/accounts/follow-background.' + ext
if os.path.isfile(mediaFilename):
if self._etag_exists(mediaFilename):
# The file has not changed
self._304()
return
tries = 0
mediaBinary = None
while tries < 5:
try:
with open(mediaFilename, 'rb') as avFile:
mediaBinary = avFile.read()
break
except Exception as e:
print(e)
time.sleep(1)
tries += 1
if mediaBinary:
self._set_headers_etag(mediaFilename, 'image/png',
mediaBinary, cookie,
callingDomain)
self._write(mediaBinary)
return
self._404()
return
tries = 0
mediaBinary = None
while tries < 5:
try:
with open(mediaFilename, 'rb') as avFile:
mediaBinary = avFile.read()
break
except Exception as e:
print(e)
time.sleep(1)
tries += 1
if mediaBinary:
self._set_headers_etag(mediaFilename, 'image/' + ext,
mediaBinary, cookie,
callingDomain)
self._write(mediaBinary)
return
self._404()
return
self._benchmarkGETtimings(GETstartTime, GETtimings, 18)

View File

@ -646,8 +646,7 @@ def setThemeImages(baseDir: str, name: str) -> None:
else:
backgroundImageFilename = \
baseDir + '/img/' + backgroundType + \
'_background_' + \
themeNameLower + '.' + ext
'_background_' + themeNameLower + '.' + ext
if os.path.isfile(backgroundImageFilename):
try: