diff --git a/daemon.py b/daemon.py index 796734561..3e494422d 100644 --- a/daemon.py +++ b/daemon.py @@ -11169,6 +11169,53 @@ class PubServer(BaseHTTPRequestHandler): self._404() return True + def _showDefaultProfileBackground(self, callingDomain: str, path: str, + baseDir: str, themeName: str, + GETstartTime, GETtimings: {}) -> bool: + """If a background image is missing after searching for a handle + then substitute this image + """ + imageExtensions = getImageExtensions() + for ext in imageExtensions: + bgFilename = \ + baseDir + '/theme/' + themeName + '/image.' + ext + if os.path.isfile(bgFilename): + if self._etag_exists(bgFilename): + # The file has not changed + self._304() + return True + + tries = 0 + bgBinary = None + while tries < 5: + try: + with open(bgFilename, 'rb') as avFile: + bgBinary = avFile.read() + break + except Exception as e: + print('ERROR: _showDefaultProfileBackground ' + + str(tries) + ' ' + str(e)) + time.sleep(1) + tries += 1 + if bgBinary: + if ext == 'jpg': + ext = 'jpeg' + self._set_headers_etag(bgFilename, + 'image/' + ext, + bgBinary, None, + self.server.domainFull, + False, None) + self._write(bgBinary) + self._benchmarkGETtimings(GETstartTime, + GETtimings, + 'search screen ' + + 'banner done', + 'background shown') + return True + + self._404() + return True + def _showShareImage(self, callingDomain: str, path: str, baseDir: str, GETstartTime, GETtimings: {}) -> bool: @@ -13005,6 +13052,13 @@ class PubServer(BaseHTTPRequestHandler): 'account qrcode done', 'search screen banner done') + if self.path.startswith('/defaultprofilebackground'): + self._showDefaultProfileBackground(callingDomain, self.path, + self.server.baseDir, + self.server.themeName, + GETstartTime, GETtimings) + return + if '-background.' in self.path: if self._showBackgroundImage(callingDomain, self.path, self.server.baseDir, diff --git a/webapp_profile.py b/webapp_profile.py index e9f9b5a45..57975c54f 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -415,6 +415,8 @@ def _getProfileHeaderAfterSearch(baseDir: str, """The header of a searched for handle, containing background image and avatar """ + if not imageUrl: + imageUrl = '/defaultprofilebackground' htmlStr = \ '\n\n
\n' + \ '