mirror of
https://github.com/facefusion/facefusion.git
synced 2026-05-01 13:57:50 +02:00
cleanup code part1
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ def test_upload_asset(test_client : TestClient) -> None:
|
||||
'file': ('invalid.txt', 'invalid'.encode(), 'text/plain')
|
||||
})
|
||||
|
||||
assert upload_response.status_code == 400
|
||||
assert upload_response.status_code == 415
|
||||
|
||||
|
||||
def test_get_assets(test_client : TestClient) -> None:
|
||||
|
||||
@@ -214,7 +214,6 @@ def test_replace_audio() -> None:
|
||||
|
||||
def test_sanitize_audio() -> None:
|
||||
audio_path = get_test_example_file('source.mp3')
|
||||
|
||||
output_strict_path = get_test_output_path('output-strict.mp3')
|
||||
output_moderate_path = get_test_output_path('output-moderate.mp3')
|
||||
|
||||
@@ -235,7 +234,6 @@ def test_sanitize_image() -> None:
|
||||
|
||||
def test_sanitize_video() -> None:
|
||||
video_path = get_test_example_file('target-240p.mp4')
|
||||
|
||||
output_strict_path = get_test_output_path('output-strict.mp4')
|
||||
output_moderate_path = get_test_output_path('output-moderate.mp4')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user