From 0ca557d6e1a962547fbb0e48e79b4371132f52e4 Mon Sep 17 00:00:00 2001 From: Pradip-p Date: Tue, 29 Oct 2024 10:12:49 +0545 Subject: [PATCH] fix: issues slove on updated imgaes delete on s3 buckets --- src/backend/app/projects/project_routes.py | 27 ++++------------------ 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/src/backend/app/projects/project_routes.py b/src/backend/app/projects/project_routes.py index b05c9a4b..eddc5c22 100644 --- a/src/backend/app/projects/project_routes.py +++ b/src/backend/app/projects/project_routes.py @@ -313,20 +313,17 @@ async def generate_presigned_url( # Process each image in the request for image in data.image_name: - # Construct the image path - image_path = ( - f"projects/{data.project_id}/{data.task_id}/images/" - if replace_existing - else f"projects/{data.project_id}/{data.task_id}/images/{image}" - ) + image_path = f"projects/{data.project_id}/{data.task_id}/images/{image}" + # If replace_existing is True, delete the image first if replace_existing: + image_dir = f"projects/{data.project_id}/{data.task_id}/images/" try: # Prepare the list of objects to delete (recursively if necessary) delete_object_list = map( lambda x: DeleteObject(x.object_name), client.list_objects( - settings.S3_BUCKET_NAME, image_path, recursive=True + settings.S3_BUCKET_NAME, image_dir, recursive=True ), ) @@ -343,22 +340,6 @@ async def generate_presigned_url( detail=f"Failed to delete existing image: {error}", ) - # # Update task as images uploaded - # pool = await database.get_db_connection_pool() - # current_task_state = await task_logic.get_task_state( - # conn, data.project_id, data.task_id - # ) - # async with pool.connection() as conn: - # await task_logic.update_task_state( - # conn, - # data.project_id, - # data.task_id, - # data.user_id, - # "Image re-upload", - # current_task_state, - # final_state=State.IMAGE_UPLOADED, - # updated_at=timestamp(), - # ) except Exception as e: raise HTTPException( status_code=HTTPStatus.BAD_REQUEST,