mirror of
https://github.com/tcsenpai/Zundler.git
synced 2025-06-07 03:55:26 +00:00
Use better mime type guessing
This commit is contained in:
parent
0147b332d5
commit
223b88639f
@ -29,6 +29,7 @@ install_requires =
|
|||||||
sphinx
|
sphinx
|
||||||
bs4
|
bs4
|
||||||
lxml
|
lxml
|
||||||
|
python-magic
|
||||||
importlib-metadata; python_version<"3.8"
|
importlib-metadata; python_version<"3.8"
|
||||||
|
|
||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
|
@ -249,9 +249,13 @@ def embed_css_resources(css, filename):
|
|||||||
|
|
||||||
|
|
||||||
def mime_type_from_bytes(buffer):
|
def mime_type_from_bytes(buffer):
|
||||||
from io import BytesIO
|
try:
|
||||||
from sphinx.util.images import guess_mimetype_for_stream
|
import magic
|
||||||
mime_type = guess_mimetype_for_stream(BytesIO(buffer))
|
mime_type = magic.Magic(mime=True).from_buffer(buffer)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("Error while guessing mime type: " + str(buffer[:10]) + '...')
|
||||||
|
logger.error(str(e))
|
||||||
|
return 'application/octet-stream'
|
||||||
return mime_type
|
return mime_type
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user