Skip to content
Extraits de code Groupes Projets
Valider e073f697 rédigé par Tulir Asokan's avatar Tulir Asokan
Parcourir les fichiers

Make magic optional

parent 14059764
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -5,13 +5,18 @@ ...@@ -5,13 +5,18 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
from typing import Dict, Optional from typing import Dict, Optional
from hashlib import sha256 from hashlib import sha256
import mimetypes
import argparse import argparse
import os.path import os.path
import asyncio import asyncio
import string import string
import json import json
try:
import magic import magic
except ImportError:
print("[Warning] Magic is not installed, using file extensions to guess mime types")
magic = None
from .lib import matrix, util from .lib import matrix, util
...@@ -31,7 +36,11 @@ async def upload_sticker(file: str, directory: str, old_stickers: Dict[str, matr ...@@ -31,7 +36,11 @@ async def upload_sticker(file: str, directory: str, old_stickers: Dict[str, matr
path = os.path.join(directory, file) path = os.path.join(directory, file)
if not os.path.isfile(path): if not os.path.isfile(path):
return None return None
if magic:
mime = magic.from_file(path, mime=True) mime = magic.from_file(path, mime=True)
else:
mime, _ = mimetypes.guess_type(file)
if not mime.startswith("image/"): if not mime.startswith("image/"):
return None return None
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter