refac
This commit is contained in:
1 parent
74f95a9b0d
commit
42c86e7283
1 file changed
+44
-26
@@ -112,38 +112,56 @@ 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):
|
||||||
file_path_processed = await asyncio.to_thread(Storage.get_file, file_path)
|
# Audio / STT-supported files → transcribe then index
|
||||||
result = await asyncio.to_thread(
|
file_path_processed = await asyncio.to_thread(Storage.get_file, file_path)
|
||||||
transcribe,
|
result = await asyncio.to_thread(
|
||||||
request,
|
transcribe,
|
||||||
file_path_processed,
|
request,
|
||||||
file_metadata,
|
file_path_processed,
|
||||||
user,
|
file_metadata,
|
||||||
)
|
user,
|
||||||
|
)
|
||||||
|
await process_file(
|
||||||
|
request,
|
||||||
|
ProcessFileForm(file_id=file_item.id, content=result.get('text', '')),
|
||||||
|
user=user,
|
||||||
|
db=db_session,
|
||||||
|
)
|
||||||
|
|
||||||
await process_file(
|
elif (
|
||||||
request,
|
content_type
|
||||||
ProcessFileForm(file_id=file_item.id, content=result.get('text', '')),
|
and content_type.startswith(('image/', 'video/'))
|
||||||
user=user,
|
and request.app.state.config.CONTENT_EXTRACTION_ENGINE != 'external'
|
||||||
db=db_session,
|
):
|
||||||
)
|
# Media files without an external extraction engine
|
||||||
elif (not content_type.startswith(('image/', 'video/'))) or (
|
if content_type.startswith('video/'):
|
||||||
request.app.state.config.CONTENT_EXTRACTION_ENGINE == 'external'
|
# Videos are stored as-is for downstream multimodal
|
||||||
):
|
# processing (Tools, vision models). Attempting text
|
||||||
await process_file(
|
# extraction causes "Timeout reached while detecting
|
||||||
request,
|
# encoding" errors.
|
||||||
ProcessFileForm(file_id=file_item.id),
|
log.info(f'Video file detected ({content_type}), skipping text extraction')
|
||||||
user=user,
|
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),
|
||||||
|
|||||||
Reference in new issue
Block a user