1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-09 11:30:00 +00:00

Output error message in case import of libmagic fails (#3104)

This commit is contained in:
Ozzie Isaacs 2024-07-20 11:31:31 +02:00
parent e3be7595e2
commit a59d20bd0f

View File

@ -29,8 +29,9 @@ log = logger.create()
try: try:
import magic import magic
error = None
except ImportError as e: except ImportError as e:
log.error("Cannot import python-magic, checking uploaded file metadata will not work: %s", e) error = "Cannot import python-magic, checking uploaded file metadata will not work: {}".format(e)
def get_temp_dir(): def get_temp_dir():
@ -46,6 +47,9 @@ def del_temp_dir():
def validate_mime_type(file_buffer, allowed_extensions): def validate_mime_type(file_buffer, allowed_extensions):
if error:
log.error(error)
return False
mime = magic.Magic(mime=True) mime = magic.Magic(mime=True)
allowed_mimetypes = list() allowed_mimetypes = list()
for x in allowed_extensions: for x in allowed_extensions: