@@ -281,20 +281,22 @@ def execute(self):
281281 except AppValidationException as e :
282282 self ._response .errors = e
283283 return self ._response
284-
285- backend_response = self ._backend_service .attach_files (
286- project_id = self ._project .uuid ,
287- folder_id = self ._folder .uuid ,
288- team_id = self ._project .team_id ,
289- files = to_upload ,
290- annotation_status_code = self .annotation_status_code ,
291- upload_state_code = self .upload_state_code ,
292- meta = meta ,
293- )
294- if isinstance (backend_response , dict ) and "error" in backend_response :
295- self ._response .errors = AppException (backend_response ["error" ])
284+ if to_upload :
285+ backend_response = self ._backend_service .attach_files (
286+ project_id = self ._project .uuid ,
287+ folder_id = self ._folder .uuid ,
288+ team_id = self ._project .team_id ,
289+ files = to_upload ,
290+ annotation_status_code = self .annotation_status_code ,
291+ upload_state_code = self .upload_state_code ,
292+ meta = meta ,
293+ )
294+ if isinstance (backend_response , dict ) and "error" in backend_response :
295+ self ._response .errors = AppException (backend_response ["error" ])
296+ else :
297+ self ._response .data = backend_response , duplications
296298 else :
297- self ._response .data = backend_response , duplications
299+ self ._response .data = [] , duplications
298300 return self ._response
299301
300302
@@ -1089,7 +1091,7 @@ def __init__(
10891091 self ,
10901092 project : ProjectEntity ,
10911093 folder : FolderEntity ,
1092- s3_repo : BaseManageableRepository ,
1094+ s3_repo ,
10931095 settings : BaseManageableRepository ,
10941096 backend_client : SuerannotateServiceProvider ,
10951097 annotation_status : str ,
@@ -1113,15 +1115,19 @@ def __init__(
11131115 self ._annotation_status = annotation_status
11141116 self ._auth_data = None
11151117
1116- def validate_auth_data (self ):
1117- response = self ._backend_client .get_s3_upload_auth_token (
1118- team_id = self ._project .team_id ,
1119- folder_id = self ._folder .uuid ,
1120- project_id = self ._project .uuid ,
1118+ @property
1119+ def s3_repo (self ):
1120+ self ._auth_data = self ._backend_client .get_s3_upload_auth_token (
1121+ self ._project .team_id , self ._folder .uuid , self ._project .uuid
1122+ )
1123+ if "error" in self ._auth_data :
1124+ raise AppException (self ._auth_data .get ("error" ))
1125+ return self ._s3_repo (
1126+ self ._auth_data ["accessKeyId" ],
1127+ self ._auth_data ["secretAccessKey" ],
1128+ self ._auth_data ["sessionToken" ],
1129+ self ._auth_data ["bucket" ],
11211130 )
1122- if "error" in response :
1123- raise AppException (response .get ("error" ))
1124- self ._auth_data = response
11251131
11261132 def validate_project_type (self ):
11271133 if self ._project .project_type in [
@@ -1195,7 +1201,7 @@ def execute(self) -> Response:
11951201 else Path (self ._image_path ).name ,
11961202 project_settings = self ._settings .get_all (),
11971203 image = image_bytes ,
1198- s3_repo = self ._s3_repo ,
1204+ s3_repo = self .s3_repo ,
11991205 upload_path = self .auth_data ["filePath" ],
12001206 image_quality_in_editor = self ._image_quality_in_editor ,
12011207 ).execute ()
@@ -1459,7 +1465,7 @@ def execute(self):
14591465 folder = self ._folder ,
14601466 backend_service_provider = self ._backend_client ,
14611467 attachments = [
1462- image .entity for image in uploaded_images [i : i + 100 ]
1468+ image .entity for image in uploaded_images [i : i + 100 ] # noqa: E203
14631469 ],
14641470 annotation_status = self ._annotation_status ,
14651471 upload_state_code = constances .UploadState .BASIC .value ,
@@ -1581,6 +1587,27 @@ def __init__(
15811587 self ._annotation_status = annotation_status
15821588 self ._image_quality_in_editor = image_quality_in_editor
15831589 self ._settings = settings
1590+ self ._auth_data = None
1591+
1592+ @property
1593+ def auth_data (self ):
1594+ if not self ._auth_data :
1595+ self ._auth_data = self ._backend_service .get_s3_upload_auth_token (
1596+ self ._project .team_id , self ._folder .uuid , self ._project .uuid
1597+ )
1598+ return self ._auth_data
1599+
1600+ @property
1601+ def s3_repo (self ):
1602+
1603+ if "error" in self .auth_data :
1604+ raise AppException (self ._auth_data .get ("error" ))
1605+ return self ._s3_repo (
1606+ self .auth_data ["accessKeyId" ],
1607+ self .auth_data ["secretAccessKey" ],
1608+ self .auth_data ["sessionToken" ],
1609+ self .auth_data ["bucket" ],
1610+ )
15841611
15851612 def validate_limitations (self ):
15861613 response = self ._backend_service .get_limitations (
@@ -1625,18 +1652,6 @@ def validate_annotation_status(self):
16251652 else :
16261653 self ._annotation_status = constances .AnnotationStatus .NOT_STARTED
16271654
1628- def get_auth_data (self , project_id : int , team_id : int , folder_id : int ):
1629- response = self ._backend_service .get_s3_upload_auth_token (
1630- team_id , folder_id , project_id
1631- )
1632- if "error" in response :
1633- raise AppException (response .get ("error" ))
1634- return response
1635-
1636- @property
1637- def s3_repo (self ):
1638- return self ._s3_repo
1639-
16401655 def upload_image (self , image_url , image_name = None ):
16411656 download_response = DownloadImageFromPublicUrlUseCase (
16421657 project = self ._project , image_url = image_url , image_name = image_name
@@ -1662,10 +1677,8 @@ def upload_image(self, image_url, image_name=None):
16621677 project_settings = self ._settings ,
16631678 image_path = image_name ,
16641679 image = content ,
1665- s3_repo = self ._s3_repo ,
1666- upload_path = self .get_auth_data (
1667- self ._project .uuid , self ._project .team_id , self ._folder .uuid
1668- )["filePath" ],
1680+ s3_repo = self .s3_repo ,
1681+ upload_path = self .auth_data ["filePath" ],
16691682 image_quality_in_editor = self ._image_quality_in_editor ,
16701683 ).execute ()
16711684
@@ -1912,7 +1925,7 @@ def execute(self):
19121925 response = AttachFileUrlsUseCase (
19131926 project = self ._project ,
19141927 folder = self ._folder ,
1915- attachments = self ._attachments [i : i + 500 ], # noqa: E203
1928+ attachments = self ._attachments [i : i + self . CHUNK_SIZE ], # noqa: E203
19161929 backend_service_provider = self ._backend_service ,
19171930 annotation_status = self ._annotation_status ,
19181931 upload_state_code = self ._upload_state_code ,
@@ -1938,7 +1951,7 @@ def __init__(
19381951 to_folder : FolderEntity ,
19391952 backend_service : SuerannotateServiceProvider ,
19401953 images : BaseManageableRepository ,
1941- to_upload_s3_repo : BaseManageableRepository ,
1954+ s3_repo ,
19421955 project_settings : List [ProjectSettingEntity ],
19431956 include_annotations : Optional [bool ] = True ,
19441957 copy_annotation_status : Optional [bool ] = True ,
@@ -1951,7 +1964,7 @@ def __init__(
19511964 self ._image_name = image_name
19521965 self ._to_project = to_project
19531966 self ._to_folder = to_folder
1954- self ._to_upload_s3_repo = to_upload_s3_repo
1967+ self ._s3_repo = s3_repo
19551968 self ._project_settings = project_settings
19561969 self ._include_annotations = include_annotations
19571970 self ._copy_annotation_status = copy_annotation_status
@@ -2003,6 +2016,20 @@ def validate_limitations(self):
20032016 if response .data .super_user_limit and response .data .super_user_limit .remaining_image_count < 1 :
20042017 raise AppValidationException (constances .COPY_SUPER_LIMIT_ERROR_MESSAGE )
20052018
2019+ @property
2020+ def s3_repo (self ):
2021+ self ._auth_data = self ._backend_service .get_s3_upload_auth_token (
2022+ self ._to_project .team_id , self ._to_folder .uuid , self ._to_project .uuid
2023+ )
2024+ if "error" in self ._auth_data :
2025+ raise AppException (self ._auth_data .get ("error" ))
2026+ return self ._s3_repo (
2027+ self ._auth_data ["accessKeyId" ],
2028+ self ._auth_data ["secretAccessKey" ],
2029+ self ._auth_data ["sessionToken" ],
2030+ self ._auth_data ["bucket" ],
2031+ )
2032+
20062033 def execute (self ) -> Response :
20072034 if self .is_valid ():
20082035 image = (
@@ -2039,7 +2066,7 @@ def execute(self) -> Response:
20392066 image = image_bytes ,
20402067 project_settings = self ._project_settings ,
20412068 upload_path = auth_data ["filePath" ],
2042- s3_repo = self ._to_upload_s3_repo ,
2069+ s3_repo = self .s3_repo ,
20432070 ).execute ()
20442071 if s3_response .errors :
20452072 raise AppException (s3_response .errors )
0 commit comments