Display an empty img if a site icon can't be found

This improves the search result icon feature by "hiding" the site's icon
if one was not found. This happens in scenarios where a site doesn't
have a /favicon.ico due to having a unique path or using javascript to
load the icon.
main
Ben Busby 2023-10-11 11:02:20 -06:00
parent 4292ec7f63
commit 67b6110087
No known key found for this signature in database
GPG Key ID: B9B7231E01D924A1
1 changed files with 7 additions and 1 deletions

View File

@ -490,7 +490,13 @@ def element():
return send_file(io.BytesIO(empty_gif), mimetype='image/gif') return send_file(io.BytesIO(empty_gif), mimetype='image/gif')
try: try:
file_data = g.user_request.send(base_url=src_url).content response = g.user_request.send(base_url=src_url)
# Display an empty gif if the requested element couldn't be retrieved
if response.status_code != 200:
return send_file(io.BytesIO(empty_gif), mimetype='image/gif')
file_data = response.content
tmp_mem = io.BytesIO() tmp_mem = io.BytesIO()
tmp_mem.write(file_data) tmp_mem.write(file_data)
tmp_mem.seek(0) tmp_mem.seek(0)