cleanup code part1

This commit is contained in:
henryruhs
2026-05-11 16:36:23 +02:00
parent 2b76f3381f
commit 2aced392e1
4 changed files with 31 additions and 36 deletions
+9 -12
View File
@@ -109,20 +109,17 @@ async def save_asset_files(upload_files : List[UploadFile]) -> List[str]:
process_manager.start()
upload_task = asyncio.create_task(feed_upload_queue(upload_file, upload_queue))
has_file_sanitized = False
if media_type == 'audio':
has_file_sanitized = await asyncio.to_thread(ffmpeg.sanitize_audio, file_format, upload_queue.get, asset_path, api_security_strategy)
if media_type == 'image':
has_file_sanitized = await asyncio.to_thread(ffmpeg.sanitize_image, file_format, upload_queue.get, asset_path)
if media_type == 'video':
has_file_sanitized = await asyncio.to_thread(ffmpeg.sanitize_video, file_format, upload_queue.get, asset_path, api_security_strategy)
await upload_task
if has_file_sanitized:
if media_type == 'audio' and await asyncio.to_thread(ffmpeg.sanitize_audio, file_format, upload_queue.get, asset_path, api_security_strategy):
asset_paths.append(asset_path)
process_manager.end()
if media_type == 'image' and await asyncio.to_thread(ffmpeg.sanitize_image, file_format, upload_queue.get, asset_path):
asset_paths.append(asset_path)
if media_type == 'video' and await asyncio.to_thread(ffmpeg.sanitize_video, file_format, upload_queue.get, asset_path, api_security_strategy):
asset_paths.append(asset_path)
if await upload_task:
process_manager.end()
return asset_paths
+21 -21
View File
@@ -23,29 +23,29 @@ async def upload_asset(request : Request) -> Response:
form = await request.form()
upload_files = form.getlist('file')
if not validate_asset_files(upload_files):
if upload_files and validate_asset_files(upload_files):
asset_paths = await save_asset_files(upload_files)
if asset_paths:
asset_ids : List[str] = []
for asset_path in asset_paths:
asset = asset_store.create_asset(session_id, asset_type, asset_path)
if asset:
asset_id = asset.get('id')
if asset_id:
asset_ids.append(asset_id)
if asset_ids:
return JSONResponse(
{
'asset_ids': asset_ids
}, status_code = HTTP_201_CREATED)
return Response(status_code = HTTP_415_UNSUPPORTED_MEDIA_TYPE)
asset_paths = await save_asset_files(upload_files)
if asset_paths:
asset_ids : List[str] = []
for asset_path in asset_paths:
asset = asset_store.create_asset(session_id, asset_type, asset_path)
if asset:
asset_id = asset.get('id')
if asset_id:
asset_ids.append(asset_id)
if asset_ids:
return JSONResponse(
{
'asset_ids': asset_ids
}, status_code = HTTP_201_CREATED)
return Response(status_code = HTTP_400_BAD_REQUEST)