Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete from storage on delete in History page #203

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions middleware/app/api/routes/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ def delete_upload_return_done(

keys = {"upload_id": upload_id}
dynamodb.delete_item(keys)
storage.delete_folder(upload_id)

log.info("Exiting {}".format(FUNCTION_NAME))
return {"status": "Done"}
Expand Down
20 changes: 20 additions & 0 deletions middleware/app/storage/cloudflare_r2.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,25 @@ def get_file_info(self, file_path: str):
)
raise HTTPException(status_code=500, detail=str(e))

def delete_folder(self, folder_name: str):
FUNCTION_NAME = "delete_folder()"
log.info("Entering {}".format(FUNCTION_NAME))

try:
response = self.r2.list_objects_v2(Bucket=self.bucket_name, Prefix=folder_name)
if "Contents" in response:
for obj in response["Contents"]:
self.r2.delete_object(Bucket=self.bucket_name, Key=obj["Key"])
log.info("Deleted UploadID: {}".format(folder_name))
except Exception as e:
log.error(
"EXCEPTION occurred deleting folder in R2.\nERROR: {}".format(
str(e)
)
)
raise HTTPException(status_code=500, detail=str(e))

log.info("Exiting {}".format(FUNCTION_NAME))

def _get_exact_format(self, file_format):
return file_format.split("/")[-1]
4 changes: 4 additions & 0 deletions middleware/app/storage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ def is_file_present(self, file_path):
@abstractmethod
def get_file_info(self, file_path: str):
pass

@abstractmethod
def delete_folder(self, folder_name: str):
pass
Loading