mirror of https://gitlab.com/bashrc2/epicyon
Move qr code to its own method
parent
3b7d8a721f
commit
167a5e3b5e
77
daemon.py
77
daemon.py
|
@ -6872,6 +6872,44 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self._404()
|
||||
return True
|
||||
|
||||
def _showQRcode(self, callingDomain: str, path: str,
|
||||
baseDir: str, domain: str, port: int,
|
||||
GETstartTime, GETtimings: {}) -> bool:
|
||||
"""Shows a QR code for an account
|
||||
"""
|
||||
nickname = getNicknameFromActor(path)
|
||||
savePersonQrcode(baseDir, nickname, domain, port)
|
||||
qrFilename = \
|
||||
baseDir + '/accounts/' + nickname + '@' + domain + '/qrcode.png'
|
||||
if os.path.isfile(qrFilename):
|
||||
if self._etag_exists(qrFilename):
|
||||
# The file has not changed
|
||||
self._304()
|
||||
return
|
||||
|
||||
tries = 0
|
||||
mediaBinary = None
|
||||
while tries < 5:
|
||||
try:
|
||||
with open(qrFilename, 'rb') as avFile:
|
||||
mediaBinary = avFile.read()
|
||||
break
|
||||
except Exception as e:
|
||||
print(e)
|
||||
time.sleep(1)
|
||||
tries += 1
|
||||
if mediaBinary:
|
||||
self._set_headers_etag(qrFilename, 'image/png',
|
||||
mediaBinary, None,
|
||||
callingDomain)
|
||||
self._write(mediaBinary)
|
||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||
'login screen logo done',
|
||||
'account qrcode')
|
||||
return True
|
||||
self._404()
|
||||
return True
|
||||
|
||||
def do_GET(self):
|
||||
callingDomain = self.server.domainFull
|
||||
if self.headers.get('Host'):
|
||||
|
@ -7480,40 +7518,11 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
# QR code for account handle
|
||||
if '/users/' in self.path and \
|
||||
self.path.endswith('/qrcode.png'):
|
||||
nickname = getNicknameFromActor(self.path)
|
||||
savePersonQrcode(self.server.baseDir,
|
||||
nickname, self.server.domain,
|
||||
self.server.port)
|
||||
qrFilename = \
|
||||
self.server.baseDir + '/accounts/' + \
|
||||
nickname + '@' + self.server.domain + '/qrcode.png'
|
||||
if os.path.isfile(qrFilename):
|
||||
if self._etag_exists(qrFilename):
|
||||
# The file has not changed
|
||||
self._304()
|
||||
return
|
||||
|
||||
tries = 0
|
||||
mediaBinary = None
|
||||
while tries < 5:
|
||||
try:
|
||||
with open(qrFilename, 'rb') as avFile:
|
||||
mediaBinary = avFile.read()
|
||||
break
|
||||
except Exception as e:
|
||||
print(e)
|
||||
time.sleep(1)
|
||||
tries += 1
|
||||
if mediaBinary:
|
||||
self._set_headers_etag(qrFilename, 'image/png',
|
||||
mediaBinary, cookie,
|
||||
callingDomain)
|
||||
self._write(mediaBinary)
|
||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||
'login screen logo done',
|
||||
'account qrcode')
|
||||
return
|
||||
self._404()
|
||||
if self._showQRcode(callingDomain, self.path,
|
||||
self.server.baseDir,
|
||||
self.server.domain,
|
||||
self.server.port,
|
||||
GETstartTime, GETtimings):
|
||||
return
|
||||
|
||||
self._benchmarkGETtimings(GETstartTime, GETtimings,
|
||||
|
|
Loading…
Reference in New Issue