Guess mime type from filename first

It seems libmagic is too unreliable.
This commit is contained in:
Adrian Vollmer 2024-06-03 11:17:08 +02:00 committed by GitHub
parent 6b9c894ed2
commit 708733c51e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,6 +20,7 @@ import base64
from fnmatch import fnmatch
import json
import logging
import mimetypes
import os
from pathlib import Path
import re
@ -138,7 +139,9 @@ def prepare_file(filename):
_, ext = os.path.splitext(filename)
ext = ext.lower()[1:]
data = open(filename, "rb").read()
mime_type = mime_type_from_bytes(filename, data)
mime_type, _ = mimetypes.guess_type(filename)
if not mime_type:
mime_type = mime_type_from_bytes(filename, data)
base64encoded = False
if ext == "css":