This commit is contained in:
2025-08-31 00:29:53 +02:00
parent 191bd84573
commit 29611b15ca
87 changed files with 2451 additions and 0 deletions

26
app/upload/utils.py Normal file
View File

@@ -0,0 +1,26 @@
import magic
from upload.models import AbstractFile
from functools import lru_cache
@lru_cache(maxsize=128)
def get_mimetype_class_map():
mapping = {}
for cls in AbstractFile.__subclasses__():
for mt in getattr(cls, 'allowed_mimetypes', []):
mapping[mt] = cls
return mapping
def get_mimetype(file_obj):
mimetype = magic.from_buffer(file_obj.read(2048), mime=True)
file_obj.seek(0)
return mimetype
def get_upload_class_for_mimetype(mimetype):
mimetype = mimetype.lower().replace('x-', '') # normalisation légère
return get_mimetype_class_map().get(mimetype)
def create_upload(request, file_obj):
pass