Skip to content

Commit

Permalink
Update:Refactor upload function
Browse files Browse the repository at this point in the history
  • Loading branch information
Faizan-hub committed Dec 6, 2024
1 parent 5c36436 commit 5cdc122
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/server/operandi_server/routers/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ async def remove_file_group_from_workspace(

async def upload_batch_workspaces(
self,
files: List[UploadFile] = Form(...),
workspaces: List[UploadFile] = Form(...),
details: str = Form("Batch upload of workspaces"),
auth: HTTPBasicCredentials = Depends(HTTPBasic()),
) -> List[WorkspaceRsrc]:
Expand All @@ -288,7 +288,7 @@ async def upload_batch_workspaces(
"""
py_user_action = await self.user_authenticator.user_login(auth)

if len(files) > 5:
if len(workspaces) > 5:
message = "Batch upload exceeds the limit of 5 workspaces"
self.logger.error(message)
raise HTTPException(
Expand All @@ -297,12 +297,12 @@ async def upload_batch_workspaces(
)

uploaded_workspaces = []
for file in files:
for workspace in workspaces:
ws_id, ws_dir = create_resource_dir(SERVER_WORKSPACES_ROUTER)
bag_dest = f"{ws_dir}.zip"

try:
await receive_resource(file=file, resource_dst=bag_dest)
await receive_resource(file=workspace, resource_dst=bag_dest)
rmtree(ws_dir, ignore_errors=True)
validate_bag_with_handling(self.logger, bag_dst=bag_dest)
bag_info = extract_bag_info_with_handling(self.logger, bag_dst=bag_dest, ws_dir=ws_dir)
Expand Down Expand Up @@ -331,10 +331,10 @@ async def upload_batch_workspaces(
uploaded_workspaces.append(WorkspaceRsrc.from_db_workspace(db_workspace))

except Exception as error:
self.logger.error(f"Failed to process workspace {file.filename}, error: {error}")
self.logger.error(f"Failed to process workspace {workspace.filename}, error: {error}")
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=f"Error processing file {file.filename}: {str(error)}",
detail=f"Error processing file {workspace.filename}: {str(error)}",
)

return uploaded_workspaces
Expand Down

0 comments on commit 5cdc122

Please sign in to comment.