fix/refac: stt default content type

This commit is contained in:
Timothy Jaeryang Baek 2025-12-22 09:45:55 +04:00
parent 7f0ca8c4b7
commit 4ab917c74b
3 changed files with 6 additions and 3 deletions

View file

@ -1151,10 +1151,9 @@ def transcription(
user=Depends(get_verified_user), user=Depends(get_verified_user),
): ):
log.info(f"file.content_type: {file.content_type}") log.info(f"file.content_type: {file.content_type}")
stt_supported_content_types = getattr( stt_supported_content_types = getattr(
request.app.state.config, "STT_SUPPORTED_CONTENT_TYPES", [] request.app.state.config, "STT_SUPPORTED_CONTENT_TYPES", []
) or ["audio/*", "video/webm"] )
if not strict_match_mime_type(stt_supported_content_types, file.content_type): if not strict_match_mime_type(stt_supported_content_types, file.content_type):
raise HTTPException( raise HTTPException(

View file

@ -114,7 +114,7 @@ def process_uploaded_file(request, file, file_path, file_item, file_metadata, us
if file.content_type: if file.content_type:
stt_supported_content_types = getattr( stt_supported_content_types = getattr(
request.app.state.config, "STT_SUPPORTED_CONTENT_TYPES", [] request.app.state.config, "STT_SUPPORTED_CONTENT_TYPES", []
) or ["audio/*", "video/webm"] )
if strict_match_mime_type(stt_supported_content_types, file.content_type): if strict_match_mime_type(stt_supported_content_types, file.content_type):
file_path = Storage.get_file(file_path) file_path = Storage.get_file(file_path)

View file

@ -622,6 +622,10 @@ def strict_match_mime_type(supported: list[str] | str, header: str) -> Optional[
supported = [s for s in supported if s.strip() and "/" in s] supported = [s for s in supported if s.strip() and "/" in s]
if len(supported) == 0:
# Default to common types if none are specified
supported = ["audio/*", "video/webm"]
match = mimeparse.best_match(supported, header) match = mimeparse.best_match(supported, header)
if not match: if not match:
return None return None