feat: enhance media upload handling and MIME type resolution
Deploy Development / deploy (push) Successful in 34s
Test Suite / pytest-backend (push) Successful in 25s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 7s
Test Suite / playwright-tests (push) Successful in 24s
Deploy Development / deploy (push) Successful in 34s
Test Suite / pytest-backend (push) Successful in 25s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 7s
Test Suite / playwright-tests (push) Successful in 24s
- Expanded the allowed upload MIME types to include HEIC, HEIF, and QuickTime formats. - Introduced a new function to resolve MIME types based on file content, filename extensions, and client-provided content types. - Updated media upload logic in both the exercises and media assets routers to utilize the new MIME resolution function. - Adjusted frontend file input accept attributes to allow broader media types, improving user experience. - Enhanced media library components to handle HEIC/HEIF formats with appropriate fallback messaging for browser compatibility.
This commit is contained in:
1 parent
d213746bd2
commit
cc4e621f95
5 files changed
+109
-17
No files matched your search
@@ -36,7 +36,7 @@ from media_lifecycle import (
|
||||
from media_storage import get_effective_media_root, path_under_media_root
|
||||
from tenant_context import TenantContext, get_tenant_context, get_tenant_context_flexible
|
||||
|
||||
from routers.exercises import ALLOWED_UPLOAD_MIMES, _upload_limit_bytes
|
||||
from routers.exercises import _upload_limit_bytes, resolve_upload_mime_type
|
||||
|
||||
router = APIRouter(prefix="/api/media-assets", tags=["media-assets"])
|
||||
|
||||
@@ -484,12 +484,10 @@ def _ingest_library_media_file(
|
||||
detail=f"Datei zu groß (max. {max_b // (1024 * 1024)} MB)",
|
||||
)
|
||||
|
||||
mime = (content_type or "").split(";")[0].strip().lower()
|
||||
if mime not in ALLOWED_UPLOAD_MIMES:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"Dateityp nicht erlaubt: {mime or 'unbekannt'}",
|
||||
)
|
||||
try:
|
||||
mime = resolve_upload_mime_type(raw, content_type, filename)
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e)) from e
|
||||
|
||||
full_sha = hashlib.sha256(raw).hexdigest()
|
||||
cur.execute(
|
||||
@@ -532,6 +530,12 @@ def _ingest_library_media_file(
|
||||
ext = ".jpg"
|
||||
elif not ext and mime == "image/png":
|
||||
ext = ".png"
|
||||
elif not ext and mime in ("image/heic", "image/heif"):
|
||||
ext = ".heic"
|
||||
elif not ext and mime == "video/mp4":
|
||||
ext = ".mp4"
|
||||
elif not ext and mime == "video/quicktime":
|
||||
ext = ".mov"
|
||||
|
||||
media_root = get_effective_media_root(cur)
|
||||
storage_key = f"exercises/{full_sha}{ext}"
|
||||
|
||||
Reference in new issue
Block a user