This commit is contained in:
Timothy Jaeryang Baek committed 2026-05-14 02:25:16 +09:00
1 parent 74f95a9b0d
commit 42c86e7283
1 file changed
+30 -12
+30 -12
View File
@@ -112,10 +112,12 @@ async def process_uploaded_file(
if _is_text_file(file_path): if _is_text_file(file_path):
content_type = 'text/plain' content_type = 'text/plain'
if content_type: stt_supported = getattr(
stt_supported_content_types = getattr(request.app.state.config, 'STT_SUPPORTED_CONTENT_TYPES', []) request.app.state.config, 'STT_SUPPORTED_CONTENT_TYPES', []
)
if strict_match_mime_type(stt_supported_content_types, content_type): if content_type and strict_match_mime_type(stt_supported, content_type):
# Audio / STT-supported files → transcribe then index
file_path_processed = await asyncio.to_thread(Storage.get_file, file_path) file_path_processed = await asyncio.to_thread(Storage.get_file, file_path)
result = await asyncio.to_thread( result = await asyncio.to_thread(
transcribe, transcribe,
@@ -124,26 +126,42 @@ async def process_uploaded_file(
file_metadata, file_metadata,
user, user,
) )
await process_file( await process_file(
request, request,
ProcessFileForm(file_id=file_item.id, content=result.get('text', '')), ProcessFileForm(file_id=file_item.id, content=result.get('text', '')),
user=user, user=user,
db=db_session, db=db_session,
) )
elif (not content_type.startswith(('image/', 'video/'))) or (
request.app.state.config.CONTENT_EXTRACTION_ENGINE == 'external' elif (
content_type
and content_type.startswith(('image/', 'video/'))
and request.app.state.config.CONTENT_EXTRACTION_ENGINE != 'external'
): ):
await process_file( # Media files without an external extraction engine
request, if content_type.startswith('video/'):
ProcessFileForm(file_id=file_item.id), # Videos are stored as-is for downstream multimodal
user=user, # processing (Tools, vision models). Attempting text
# extraction causes "Timeout reached while detecting
# encoding" errors.
log.info(f'Video file detected ({content_type}), skipping text extraction')
await Files.update_file_data_by_id(
file_item.id,
{'status': 'completed'},
db=db_session, db=db_session,
) )
else: else:
raise Exception(f'File type {content_type} is not supported for processing') raise Exception(
f'File type {content_type} is not supported for processing'
)
else: else:
log.info(f'File type {file.content_type} is not provided, but trying to process anyway') # Documents, or any file when an external engine is configured
if not content_type:
log.info(
f'File type {file.content_type} is not provided, '
'but trying to process anyway'
)
await process_file( await process_file(
request, request,
ProcessFileForm(file_id=file_item.id), ProcessFileForm(file_id=file_item.id),