@@ -375,18 +375,32 @@ async def delete_file(
375375async def abort_multipart_upload (
376376 request : Request ,
377377 file_id : UUID ,
378- client_file : Annotated [ClientFile , Body (..., embed = True )],
378+ client_file : Annotated [ClientFileInProgramJob | ClientFile , Body (..., embed = True )],
379379 storage_client : Annotated [StorageApi , Depends (get_api_client (StorageApi ))],
380380 user_id : Annotated [PositiveInt , Depends (get_current_user_id )],
381+ webserver_api : Annotated [AuthSession , Depends (get_webserver_session )],
381382):
383+ assert file_id # nosec
382384 assert request # nosec
383385 assert user_id # nosec
384- file = DomainFile (
385- id = file_id ,
386- filename = client_file .filename ,
387- checksum = client_file .sha256_checksum ,
388- e_tag = None ,
389- )
386+
387+ if isinstance (client_file , ClientFile ):
388+ file = client_file .to_domain_model ()
389+ elif isinstance (client_file , ClientFileInProgramJob ):
390+ project = await webserver_api .get_project (project_id = client_file .job_id )
391+ if len (project .workbench ) > 1 :
392+ raise HTTPException (
393+ status_code = status .HTTP_422_UNPROCESSABLE_ENTITY ,
394+ detail = f"Job_id { project .uuid } is not a valid program job." ,
395+ )
396+ node_id = next (iter (project .workbench .keys ()))
397+ file = client_file .to_domain_model (
398+ project_id = project .uuid , node_id = NodeID (node_id )
399+ )
400+ else :
401+ err_msg = f"Invalid client_file type passed: { type (client_file )= } "
402+ raise TypeError (err_msg )
403+
390404 abort_link : URL = await storage_client .create_abort_upload_link (
391405 file = file , query = {"user_id" : str (user_id )}
392406 )
@@ -404,20 +418,32 @@ async def abort_multipart_upload(
404418async def complete_multipart_upload (
405419 request : Request ,
406420 file_id : UUID ,
407- client_file : Annotated [ClientFile , Body (...)],
421+ client_file : Annotated [ClientFileInProgramJob | ClientFile , Body (...)],
408422 uploaded_parts : Annotated [FileUploadCompletionBody , Body (...)],
409423 storage_client : Annotated [StorageApi , Depends (get_api_client (StorageApi ))],
410424 user_id : Annotated [PositiveInt , Depends (get_current_user_id )],
425+ webserver_api : Annotated [AuthSession , Depends (get_webserver_session )],
411426):
427+ assert file_id # nosec
412428 assert request # nosec
413429 assert user_id # nosec
414430
415- file = DomainFile (
416- id = file_id ,
417- filename = client_file .filename ,
418- checksum = client_file .sha256_checksum ,
419- e_tag = None ,
420- )
431+ if isinstance (client_file , ClientFile ):
432+ file = client_file .to_domain_model ()
433+ elif isinstance (client_file , ClientFileInProgramJob ):
434+ project = await webserver_api .get_project (project_id = client_file .job_id )
435+ if len (project .workbench ) > 1 :
436+ raise HTTPException (
437+ status_code = status .HTTP_422_UNPROCESSABLE_ENTITY ,
438+ detail = f"Job_id { project .uuid } is not a valid program job." ,
439+ )
440+ node_id = next (iter (project .workbench .keys ()))
441+ file = client_file .to_domain_model (
442+ project_id = project .uuid , node_id = NodeID (node_id )
443+ )
444+ else :
445+ err_msg = f"Invalid client_file type passed: { type (client_file )= } "
446+ raise TypeError (err_msg )
421447 complete_link : URL = await storage_client .create_complete_upload_link (
422448 file = file , query = {"user_id" : str (user_id )}
423449 )
0 commit comments