diff --git a/daemon.py b/daemon.py index aaf7f26b..4078d4ee 100644 --- a/daemon.py +++ b/daemon.py @@ -39,6 +39,7 @@ from matrix import getMatrixAddress from matrix import setMatrixAddress from donate import getDonationUrl from donate import setDonationUrl +from person import savePersonQrcode from person import randomizeActorImages from person import personUpgradeActor from person import activateAccount @@ -1796,6 +1797,42 @@ class PubServer(BaseHTTPRequestHandler): self._404() return + # 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) + mediaFilename = \ + self.server.baseDir + '/accounts/' + \ + nickname + '@' + self.server.domain + '/qrcode.png' + 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 + # search screen banner image if '/users/' in self.path and \ self.path.endswith('/search_banner.png'):