fix(media): support voice audio/webm uploads
Some checks failed
CI / test (push) Failing after 18s

- allow audio/webm mime type
- normalize content-type values with codec parameters before validation
- use normalized mime for extension resolution
This commit is contained in:
2026-03-08 02:48:44 +03:00
parent 66158b9070
commit 74d9163dde

View File

@@ -21,14 +21,19 @@ ALLOWED_MIME_TYPES = {
"video/webm",
"audio/mpeg",
"audio/ogg",
"audio/webm",
"audio/wav",
"application/pdf",
"application/zip",
"text/plain",
}
def _normalize_mime(file_type: str) -> str:
return file_type.split(";", maxsplit=1)[0].strip().lower()
def _extension_from_mime(file_type: str) -> str:
ext = mimetypes.guess_extension(file_type)
ext = mimetypes.guess_extension(_normalize_mime(file_type))
if not ext:
return ".bin"
if ext == ".jpe":
@@ -50,7 +55,8 @@ def _allowed_file_url_prefixes() -> tuple[str, ...]:
def _validate_media(file_type: str, file_size: int) -> None:
if file_type not in ALLOWED_MIME_TYPES:
normalized_file_type = _normalize_mime(file_type)
if normalized_file_type not in ALLOWED_MIME_TYPES:
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail="Unsupported file type")
if file_size > settings.max_upload_size_bytes:
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail="File size exceeds limit")