Fix crash trying to thumbnail invalid image

This commit is contained in:
Raphael Michel
2021-08-16 10:33:57 +02:00
parent 08cb045f2e
commit 3c64733e93
3 changed files with 20 additions and 4 deletions

View File

@@ -20,6 +20,7 @@
# <https://www.gnu.org/licenses/>.
#
import logging
# This file is based on an earlier version of pretix which was released under the Apache License 2.0. The full text of
# the Apache License 2.0 can be obtained at <http://www.apache.org/licenses/LICENSE-2.0>.
#
@@ -73,6 +74,8 @@ from pretix.helpers.thumb import get_thumbnail
from ..settings import settings_hierarkey
from .organizer import Organizer, Team
logger = logging.getLogger(__name__)
class EventMixin:
def clean(self):
@@ -534,9 +537,17 @@ class Event(EventMixin, LoggedModel):
logo_file = self.settings.get('logo_image', as_type=str, default='')[7:]
og_file = self.settings.get('og_image', as_type=str, default='')[7:]
if og_file:
img = get_thumbnail(og_file, '1200').thumb.url
try:
img = get_thumbnail(og_file, '1200').thumb.url
except:
logger.exception(f'Failed to create thumbnail of {og_file}')
img = default_storage.url(og_file)
elif logo_file:
img = get_thumbnail(logo_file, '5000x120').thumb.url
try:
img = get_thumbnail(logo_file, '5000x1200').thumb.url
except:
logger.exception(f'Failed to create thumbnail of {logo_file}')
img = default_storage.url(logo_file)
if img:
return urljoin(build_absolute_uri(self, 'presale:event.index'), img)

View File

@@ -38,5 +38,5 @@ def thumb(source, arg):
try:
return get_thumbnail(source, arg).thumb.url
except:
logger.exception('Failed to create thumbnail')
logger.exception(f'Failed to create thumbnail of {source}')
return default_storage.url(source)

View File

@@ -208,7 +208,12 @@ def price_dict(item, price):
def get_picture(event, picture):
return urljoin(build_absolute_uri(event, 'presale:event.index'), get_thumbnail(picture.name, '60x60^').thumb.url)
try:
thumb = get_thumbnail(picture.name, '60x60^').thumb.url
except:
logger.exception(f'Failed to create thumbnail of {picture.name}')
thumb = default_storage.url(picture.name)
return urljoin(build_absolute_uri(event, 'presale:event.index'), thumb)
class WidgetAPIProductList(EventListMixin, View):